r/PHPhelp • u/Successful-Shock529 • Feb 09 '26
Multi line array formatting in php-cs-fixer
I was wondering if its possible with php-cs-fixer to handle formatting multi line arrays. I don't want all arrays to be multiline but if they are deformed I would like them to be formatted. So like the following:
Unless there's a rule I'm missing this formatting doesn't happen. This leads to severely inconsistent code. Is my only course of action to write my own fixer? It's pretty annoying to have to import a custom fixer for every project.
This seems like something that should definitely be a feature of a code formatter. This is true in basically every formatter in every language. Even Intelephense does this but Intelephense is severely limited in its formatting options. I've seen some features brought up in their github for all arrays to be multi line but that seems like it would be too much because you should still have single line arrays. I just want malformed arrays to be formatted.
Any help would be appreciated.
View all comments
Show parent comment
2
u/Successful-Shock529 Feb 09 '26
Well php-cs-fixer has builtin classes to handle matching. I just didn't want to go write a custom fixer if there was an already established one out there somewhere or some builtin feature that would handle this.