Configuring CodeSniffer automatically with composer.json
Hey guys I have had some success with gettgin phpstorm to automatically detect code sniffer and setup inspections in the editor however,
its prety hit and miss.
I noticed that it would automatically pickup CodeSniffer and use it in a blank project so I thought there must be a way to also get it to use PSR12 automatically.
I tried the documented approach here:
https://www.jetbrains.com/help/phpstorm/using-php-code-sniffer.html
By using the composer script tag.
```"scripts": { "phpcs": "phpcs --standard=PSR2" }```
Does not seem to work tho. Sometimes it will show up in the inspections but using PEAR instead of PSR12 standards, sometimes it will work and other times no inspections will be configured at all.
IM testing in macos, windows, and ubuntu.
Is there something im missing? Ive tried deleting the .idea folder and invalidating caches and restarting to try and get the changes to populate to other machines after a git pull but theres no success.
Is there a reliable way to do this without having to tell each employee to manually configure phpstorm every time they clone the repo?
Ive seen theres an xml file you can get it to use but theres nothing to say what to put in this xml file to auto setup psr12.
Any ideas?
Please sign in to leave a comment.
It appears to be somewhat broken in 2019.2. I tried to reproduce that in 2019.3 EAP, and it seems to be much better there.
Could you please also confirm that? https://www.jetbrains.com/phpstorm/nextversion/
I was using EAP when I had the issue and went back to 2019.2.3 hoping for a fix.
Seems to work when using a blank or simple project but not when trying to add to a bigger project.
To be more reliable I looked at committing some files from the .idea folder but ultimately settings that I don't want shared will come along for the ride.
For now I have just oped for the configuration process to be issued out to everyone.
If any one has any ideas on how to make the inspection and the codes sniffer config shared just from cloning the repo I would love to hear it.
Bradley Hayes, regarding the original issue: automatic detection & setup of code sniffer might not work if your project already has path to code sniffer specified. See my comment at https://youtrack.jetbrains.com/issue/WI-43963#focus=streamItem-27-3119933.0-0
> If any one has any ideas on how to make the inspection and the codes sniffer config shared just from cloning the repo I would love to hear it.
Not sure if I'm missing something but:
1) quality tools configs are stored in project's /.idea/php.xml file
2) inspections are stored either in a "global" or in a "project" profile.
"Project" profile can be shared, you can store code sniffer settings there. Project inspection profiles are stored in project's /.idea/inspectionProfiles folder.