php-cs-fixer integration: inspection necessary when I just want to run "fix"?

Going through and checking my settings, I'm not entirely sure: is the built-in integration "only" for running php-cs-fixer to report the proper validation violations back to phpstorm?

Or is the integration also capable of "fix"ing the violations?

Or is it recommend to just use a regular "File Watcher" for this?

My environment:

- code is in vagrant VM via shared folders
- however it actually works to run php-cs-fixer "locally" on the host and apply the fixes (i.e. from command line), i.e. I don't require "going through the VM" which is usually slow

My goal:

- I actually don't care much about seeing violations reported in phpstorm; I just want the file to be fixed before I carry on/commit/push it

Coming back now to the question: in this case, is there even a benefit using the integration php-cs-fixer integration (because I can't see in any dialogs a "just fix it" option or so") or is a "File Watcher" the way to go anyway?

Hope I could explain it well, thanks

- Markus


Basically, there is an option to interactively fix PHP CS Fixer violations with the Alt+Enter quick-fix action:

However, the fix should be also applied on the "Code > Code Cleanup" action, so you may enable the "Cleanup" checkbox to perform the fix on commit:



Ok, thank you! This confirms my idea what the integration is supposed to do.

Unrelated, but I although I've got a working setup of php-cs-fixer, I couldn't get the integration to do anything (i.e. not even got the reports), but no errors.

I also noticed that Cleanup does more (based on the inspections) so I feel that just using a File Watcher, in my case, is overall a better fit.

I noticed that it writes the information into `.idea/watcherTasks.xml` and respects relative paths to the project and thus can also be shared amongst the team if desired.

Thanks for your answer, much appreciated!


Thank you for your reply.

As for the inspection in general, I think, we can figure out why it does not work in your setup. Just to confirm, do you have it enabled (Editor | Inspections > PHP > Quality Tools) and a ruleset selected? 


I've configured the php-cs-fixer itself and validated it works:


(sorry, couldn't write after I pasted the image above)

And enabled it in inspections:


Hmm, yeah. So far I didn't see "any effect":

- no warnings shown in the editor (also made sure it's not below my warning level threshold and temporarily changed it to error)

- enabled "code cleanup" in the commit and made commit -> it did "something" but nothing I would attribute to php-cs-fixer

Maybe it's not picking up the custom `.php_cs.dist` but I made double sure the path is correct (and on command line, all is working with php-cs-fixer).

The project itself is remote (vagrant) but I want to use php-cs-fixer local as it's faster.



I also went back to the other solution with the file watchers, BUT after trying some real world uses I often get this dialog popping up:


Basically during real life using this pops up so often, it becomes not usable to use the file watcher in this case:


Could you please try the PHP-CS-Fixer with some default ruleset first just to be sure that it works fine? I would suggest trying the "PSR2" ruleset and the following simple example:



if ($a) {
} else if ($b) { // 'elseif' rule should be triggered here



This seems to do it (do the violation rules are slightly different)


I tried custom again, but it's not picking up anything and, interestingly the PSR2 message stays… though possible I've them in the rules too.

But when I trigger violations which I know are fixed with the custom rules, nothing appears. I provide the custom ruleset path to a `.php_cs.dist` file, is this correct?

Is there  a lot to check the exact command run? I noticed that in the _php_cs.cache file I see entries which I' unfamiliar, maybe from phpstorms integration?

"\/private\/var\/folders\/km\/h64qs0bj3q1dt41mgfcqd4xr0000gn\/T\/PHP CS Fixertemp_folder9\/app\/Foo\/Bar.php": 1692179541,



Would it be possible to share your custom ruleset, so I could check it on my installation?


Thanks for sharing.

Unfortunately, I was not able to find a .php_cs.dist file there but I copied a list of rules from the "Config.php", just added it to the default .php_cs.dist setRules, configured its usage in PhpStorm and voila (the same example as above but with your rules):



Please sign in to leave a comment.