Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

GodziLaravel's avatar

Best PhpStorm tool to format code

Hello ,

Is there any tool in PhpStorm to format code except the ctrl+alt+l?

thanks

0 likes
3 replies
tokoiwesley's avatar

You can always set an alternative key combination for that e.g. Ctrl+Shift+L (especially if you are working from an operating system that already has Ctrl+Alt+L combination assigned for a different task - like Lock Screen.

diegoaurino's avatar

Hello, Mostafa ! What I do is to combine php-cs-fixers with auto-formatting. Especially, I created a macro that substitutes Crtl + S to handle it automatically for me. Thus, every time I save my code, it autoformats and applies my rules for php-cs-fixer.

You can find more about PHP-CS-Fixers here:

[https://laracasts.com/series/how-to-be-awesome-in-phpstorm/episodes/26] - That one is a lesson! [https://github.com/FriendsOfPHP/PHP-CS-Fixer] - Official github for PHP-CS-fixer!

And take a look at the first answer on this StackOverflow thread about how to create a macro to substitute the default Crtl + S:  [https://stackoverflow.com/questions/12496669/code-reformatting-on-save-in-phpstorm].

Here are the rules I use for my php-cs-fixer: 

fix $FileDir$/$FileName$ --rules=@PSR2,array_indentation,blank_line_before_return,blank_line_after_namespace,blank_line_after_opening_tag,blank_line_before_statement,cast_spaces,class_attributes_separation,elseif,no_extra_blank_lines,no_trailing_whitespace,no_unused_imports,not_operator_with_successor_space,not_operator_with_space,ordered_class_elements,object_operator_without_whitespace,ordered_imports,ternary_operator_spaces

You can also apply PHP Code Sniffer inspections.

Good luck!

1 like

Please or to participate in this conversation.