New Code Style Options in PhpStorm 2017.1

PhpStorm 2017.1 brings a smorgasbord of new code style settings so you can get your code looking just how you like it.

We all know that having your code formatted the right way is important – after all, the Tabs vs Spaces debate has divided many communities (it’s spaces for what it’s worth). PhpStorm 2017.1 gives you some new code style options so you can get your code looking just so. Most of these changes were requested by users on our issue tracker, YouTrack.

We’ve added a new option in code styles which will remove the () from a new call when you don’t pass any constructor arguments. You can find the setting under Settings | Code Style | PHP | Wrapping and Braces | Function/constructor call arguments | Place ‘()’ for constructor.

To make sure you consistently use elseif or else if (whichever you prefer),  you can configure PhpStorm to format elseif to else if (or vice versa) using Code Style | PHP | Other | Convert else if/elseif to: and then selecting the format you want to use.

Something that’s been annoying me slightly is PhpStorm not letting me enforce a new line between <?php and the namespace declaration. You can find the setting under Code Style | PHP | Blank Lines | Before namespace. In writing this very blog post we also realised that this won’t solve the problem for everyone because of PHP 7’s declare(strict_types=1) declaration being the first line in a file – we’ve opened a ticket for that so look out for it in the future.

And speaking about PHP 7, there’s a new feature to enforce spaces around the equals sign in a declare(strict_types=1) declaration. The proposed PSR-12 standard does say that these declarations should have no whitespace in them, but if your own coding style differs, you can enforce the spaces using  Code Style | PHP | Spaces | Around Operators | Assignment in declare statement.

We’re trying to make sure your code style looks exactly how you want it to, so let us know what you think – or if we’re missing anything.

– Gary & The PhpStorm Team

 

About Gary Hockin

Gary Hockin has been creating code to power web applications for 15 years, the last three of them at an extraordinary level. He is handsome, talented, funny and articulate, and also extremely modest. Gary is a valued contributor to Zend Framework 2 and is a member of the community review team. He's married and has two wonderful children, and when he's not coding, writing about code, speaking about code or reading about code, he can usually be found in the pub playing pool.
This entry was posted in Cool Feature, Newsletter. Bookmark the permalink.