Code Style in PhpStorm

I’ve previous talked about how you can integrate Editor Config into your workflow with tools like PhpStorm but of course, the IDE is so full-featured, that it can also be used to set standards within your code natively. Let’s explain how to pick a standard for PHP in this blog post.

To begin, fire up PhpStorm with a project of your choosing.

Now press Control-Alt-S (on Windows) to bring up the settings. You can get to them another way under File > Settings... should you be on another OS or prefer menus.

From here, go to Editor > Code Style > PHP or the language that you prefer.

Next, click on Set from... which you can find on the right hand side, near the top.

Next, choose the style you prefer and then click OK.

I’ve chosen PSR 12, but you can see that there are options for Laravel, Symfony etc.

If you like, you can also adapt it to suit your preferences. In my case, I went to the PHPDoc menu and changed some of the options over blank lines etc.

Lastly, find some code and press the following key combination to reformat it based on the code style you selected: Control-Alt-L or from the menu: Code > Reformat Code.

No excuses about poor coding style, now!


Hi! Did you find this useful or interesting? I have an email list coming soon, but in the meantime, if you ready anything you fancy chatting about, I would love to hear from you. You can contact me here or at stephen ‘at’ logicalmoon.com