How can I set up that the code is reformatted automatically on saving?
So I don't always have to press Ctrl + Alt + L.
Actually it is possible.
The idea is to record a very simple macro that selects all the lines (Ctrl+A), formats (Ctrl+Alt+L), deselect all (Up and Down arrow) and saves a file (Ctrl+S), and bind this macro to Ctrl+S.
Free Ctrl+S changing keyboard shortcut for "Save all"
Record the macro
Assign Ctrl+S to "Format and Save"
Finally, enjoy PhpStorm!
Checked on PHPStorm 2020 & greater versions and found a plugin named Save Action. But make sure you configure for new and exisiting projects.
You can also export your PHPStorm settings and then unzip & replace/create the following :-
<application>
<component name="ActionMacroManager">
<macro name="Format & Save">
<action id="ReformatCode"/>
<action id="SaveAll"/>
</macro>
</component>
</application>
<keymap version="1" name="Default copy" parent="Default for XWin">
<action id="DBNavigator.Actions.SourceEditor.Save"/>
<action id="Macro.Format & Save">
<keyboard-shortcut first-keystroke="ctrl s"/>
</action>
<action id="SaveAll">
<keyboard-shortcut first-keystroke="shift ctrl alt s"/>
</action>
</keymap>
Now Zip it back & import it & whenever you press ctrl+s - Auto Code Format will be done.