Set a margin in PhpStorm to wrap DocBlock comments

Published

Since we do a lot of WordPress development work and like to keep our code well documented, we follow the WordPress guide lines on how to write our 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

We hope you found this useful!

Leave a comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.