cytopia / devilbox

A modern Docker LAMP stack and MEAN stack for local development
http://devilbox.org
MIT License
4.4k stars 654 forks source link

[Howto]: Add new coding standard to phpcs #986

Closed BWBama85 closed 1 year ago

BWBama85 commented 1 year ago

Have you already checked elsewhere?

What are you struggling with?

I would like to add a new coding standard for phpcs in the php container I am using. I run multiple php versions, if that matters.

What have you tried already?

I have tried searching and have poked around the container but can not see where or how standards should be installed.

phpcs -vv shows me this:

devilbox@php-8.1.14 in /shared/httpd/xenforo/htdocs/src/addons/TheWilsonNet/SeedAttachments $ phpcs -vv
Processing ruleset /shared/httpd/xenforo/htdocs/src/addons/TheWilsonNet/SeedAttachments/phpcs.xml
        => set config value testVersion: 7.4
        Processing rule "Generic.PHP.Syntax"
                => phar:///usr/local/bin/phpcs/src/Standards/Generic/Sniffs/PHP/SyntaxSniff.php
        Processing rule "PHPCompatibility"
                => PHPCompatibility
ERROR: Referenced sniff "PHPCompatibility" does not exist

Run "phpcs --help" for usage information

As you can see, I have a phpcs.xml that is trying to use PHPCompatibility but it is not installed as a coding standard in the container.

What is your goal?

Add new coding standards to phpcs in a php container.

userwiths commented 1 year ago

Hello, was messing with my local config to check around this issue. You can try this, run composer global require phpcompatibility/php-compatibility.

After that take the current installed_paths value. Run phpcs --config-show take the value of installed_paths, it should be a path (or a few paths separated with a comma ,). And finally add the path to the PHPCompatibility to the other path. You can check if its added correctly with phpcs -i should mention that PHPCompatibility is installed.

After that you should be ok to add your own codding standard

For example: I run php --config-show And receive

installed_paths: ~/a/b/c,~/d/e/f

Then I'd run

phpcs --config-set installed_paths ~/a/b/c,~/d/e/f,~/.composer/vendor/phpcompatibility/php-compatibility/PHPCompatibility

Hope this helps ~