This standard follows the (Symfony standards)[https://symfony.com/doc/current/contributing/code/standards.html] with with the following exceptions:
- It does not require the license on top of every file.
- It allows to have multiline function arguments.
-
Install PHP code sniffer: https://github.com/squizlabs/PHP_CodeSniffer#installation
-
Require package globally using composer:
$ composer global require "perceptiontech/php-coding-standard"
-
Add the coding standard to the PHP_CodeSniffer install path (under MacOS and Linux):
$ phpcs --config-set installed_paths ~/.composer/vendor/perceptiontech/php-coding-standard
Be aware that, if you already have installed paths, they will be lost. If so, you will have to execute:
$ phpcs --config-set installed_paths ~/.composer/vendor/perceptiontech/php-coding-standard,/path/to/already/insatlled/standard/
-
Check the installed standards for "Perception":
$ phpcs -i
-
Go to quality tools, unfold the Code Sniffer option and toggle the configuration by clicking on
...
: -
Set the path to your local PHPCode_Sniffer binary and validate it:
-
Go to Editor > Inspections > PHP > Quality tools > PHP Code Sniffer validation
-
Enable the configuration, refresh the "Coding standard" and select "Perception". Configuration should be as it follows:
(NOTE: set the severity as "warning". Otherwise, it is difficult to spot the errors within the editor)
-
After this configuration, PHPStorm should inform you whenever a piece of code is not correct according to the rules: