PHP Coding Standard
This repository contains rulesets for PHP CodeSniffer and PHP Mess Detector along with some custom rules. These standards are followed internally at Froiden (www.froiden.com), (*1)
Installation
Install this repository globally using composer:, (*2)
composer global require froiden/php_standard
Always use the latest version of the repository., (*3)
Setup
The project will be installed in global composer folder on your PC.
* Mac: .composer/vendor
folder in your home directory
* Windows: AppData/Roaming/Composer/vendor
folder in your user directory
* Ubuntu: .config/composer/vendor
folder in your home directory, (*4)
You follow the steps respective to your favourite IDE to configure PHP CodeSniffer and PHP MessDetector and point to the two rulesets in the installation folder.
* ruleset.xml - For CodeSniffer
* rulesetmd.xml - For MessDetector, (*5)
Attribution
Some sniffs in this repository have been derived from original PHP_CodeSniffer project. Credits for those go to the respective developers., (*6)
VS Code SETUP
Install the extension name PHP Sniffer by wongjn, (*7)
After Activation add the below file to settings.json file, (*8)
For Mac, (*9)
"phpSniffer.standard": "~/.composer/vendor/froiden/php_standard/ruleset.xml",
For Linux, (*10)
"phpSniffer.standard": "~/.config/composer/vendor/froiden/php_standard/ruleset.xml",
For Windows, (*11)
"phpSniffer.standard": "%userprofile%/AppData/Roaming/Composer/vendor/froiden/php_standard/ruleset.xml",
, (*12)
To check, (*13)
phpcs --standard=<PATH_OF_RULESET> <SPACE> <PATH_OF_FILEs_CHECK>
TO fix, (*14)
phpcbf --standard=<PATH_OF_RULESET> <SPACE> <PATH_OF_FILEs_CHECK>
Ignoring a file, (*15)
// @codingStandardsIgnoreFile
// phpcs:ignoreFile
Ignoring a line, (*16)
// @codingStandardsIgnoreLine
// phpcs:ignore
Ignoring a block, (*17)
// @codingStandardsIgnoreStart
// phpcs:disable
// @codingStandardsIgnoreEnd
// phpcs:enable