So recently I have seen many developers in the PHP community ordering their use statements by length. I always wondered how to do this in PhpStorm. I think I have finally found a solution but I guess I am doing something wrong here and it is not working.
So a tool called PHP-CS-Fixer has an option to do this. And I know I can use this tool with PhpStorm using Tools -> External Tools
and clicking on the +
sign and then configuring it.
Note: I pulled the tool using Composer like so composer global require friendsofphp/php-cs-fixer
So my configuration of the external tool in PhpStorm looks like so:
- Program:
/Users/rohan0793/.composer/vendor/bin/php-cs-fixer
- Arguments:
fix --rules='{"ordered_imports": {"sort_algorithm":"length"}}' $FileDir$/$FileName$
- Working directory:
$ProjectFileDir$
But when I ran it, I saw this error:
The rules contain unknown fixers: "'{ordered_imports{sort_algorithm:length}}'".
So I guess I am doing something wrong here while configuring it but cannot seem to figure out what. Any idea anyone?