Set a margin in PhpStorm to wrap DocBlock comments

Since I do a lot of WordPress development work and like to keep my code well documented, I follow the WordPress guide lines on how to write my documentation using PHP DocBlock. The WordPress guidelines specify that…

DocBlock text should wrap to the next line after 80 characters of text. If the DocBlock itself is indented on the left 20 character positions, the wrap could occur at position 100, but should not extend beyond a total of 120 characters wide.

The easiest way to know when your comment line has reached 80 characters of text, is to setup a margin. Creating a margin in PhpStorm is quite easy to do and you can even set PhpStorm to auto-wrapping against your margin (it will automatically add a new line to your comment once you reach the margin).

There is one catch though, there is currently no way to separate auto-wrapping between comments and code. What that means is that your code will also auto-wrap once you reach your margin. Hopefully this will be fixed in the future.

So to setup a margin, you simply go in to Preferences, select Editor and then Code Style. As per the screenshot below, set your margin and auto-wrapping if you want that enabled too.

PhpStorm Doc Block Margin Wrapping

Enjoyed this content? Get an article like this delivered to your inbox every Tuesday...