phpcs doesn't pick up coding standards

I'm in the middle of evaluating the purchase of PhpStorm and currently I'm looking at the code formatting functionality but I don't seem to be getting it to work as expected.

I use PhpStorm 2019.1.2 on macOS Mojave

I have a Drupal 8.6.x application in ~/path/to/dev/web setup with composer. I use DrupalVM to run the site.

As per instructions here: https://www.jetbrains.com/help/phpstorm/drupal-support.html#drupal_set_code_style

I set up PhpStorm to use the Drupal code standards.

Settings > Lang & Fr > PHP > Quality Tools > Code Sniffer 

is set to Local with path set to ~/path/to/dev/vendor/bin/phpcs

Path is validated and found OK.

Path to phpcbf is set to ~/path/to/dev/vendor/bin/phpcbf (which is in that location)

PHP CS Fixer is not set.

Settings > Editor > Inspections > Quality Tools > PHP Code Sniffer Validation 

- Show sniff name is set

- Installed standard path is set to ~/path/to/dev/vendor/drupal/coder/coder_sniffer/Drupal

- Coding standard is set to Drupal

 

When I open one of my files (~/path/to/dev/web/modules/custom/my_module/src/Controller/MyController.php) the warnings are shown.

When I choose Code > Reformat Code, the code is reformatted according to the Drupal standard (2 spaces, brace on the same line as the function e.g.).

However, the file shows many warnings and when I hover over the line I see 'phpcs: PEAR.......' warnings.

When I run Code > Code inspections

I get lots of PEAR related warnings.

I have already spent a day trying to figure this out. Restarting PhpStorm, clearing it's caches, starting from scratch adding the project.

I'm at a loss here what to do.

 

 

1 comment
Comment actions Permalink

I think I found a solution:

when I changed the coding standard to 'DrupalPractice' I got an error that the DrupalPractice coding standard was not defined, even though I had set it in the 'installed path' in the Settings.

I finally added the path to drupal/code_sniffer to the paths in Settings > Lang & Frame > PHP > Include Path

and it looks like it now works.

1

Please sign in to leave a comment.