Search code examples
phpvisual-studio-codephpcs

PHP coding standards - Visual Studio code


I'm trying to implement other coding standards for phpcs. Currently, I have setup phpcs for visual studio code and I have the following coding standards

current/path> phpcs -i
The installed coding standards are MySource, PEAR, PSR1, PSR2, Squiz and Zend

I want to set up other standards listed here: php-fig

For example PSR4

How do I go about setting these standards for my development?


Solution

  • You may set the default_standard used by phpcs using the following command:

    phpcs --config-set default_standard <value>
    

    or when using composer dependency manager from the root of your project issue the following command:

    ./vendor/bin/phpcs --config-set default_standard <value>
    

    Keep in mind that PS4 is autloading standard, not an coding standard.

    You can create a custom, your own, coding standard and then you can try to install your custom coding standard:

    phpcs --config-set installed_paths <path/to/custom/coding/standard>
    

    or when using composer dependency manager from the root of your project issue the following command:

    ./vendor/bin/phpcs --config-set installed_paths <path/to/custom/coding/standard> 
    

    Hope it helps.