PHP Coding Standards of Pilot'in (inspired & respecting mostly WordPress Coding Standards)
- Having
composer
installed:
- Having
PHP Code Sniffer
installed:
composer global require "squizlabs/php_codesniffer=*"
- Having
WordPress Coding Standards
installed:
composer global require dealerdirect/phpcodesniffer-composer-installer phpcompatibility/phpcompatibility-wp squizlabs/php_codesniffer wp-coding-standards/wpcs
- Clone this repo somewhere on your drive (or you can just download this repo and unzip it but it's not going to be synced / updated)
- Get the current path config of phpcs using:
phpcs --config-show
- Copy the paths after "installed_paths:"
- Paste it somewhere and append the path of your folder containing the "PilotIn" folder with a comma
For reference, mine looks like this: C:\composer\vendor/phpcompatibility/php-compatibility,C:\composer\vendor/phpcompatibility/phpcompatibility-paragonie,C:\composer\vendor/phpcompatibility/phpcompatibility-wp,C:\composer\vendor/wp-coding-standards/wpcs,C:\Users\Administrateur\Documents\PLUGINS DEV\PilotIn-Coding-Standards\PilotIn
- Give the new paths to phpcs using this command & change
your/paths/goes/here
:
phpcs --config-set installed_paths your/paths/goes/here
Example: phpcs --config-set installed_paths C:\composer\vendor/phpcompatibility/php-compatibility,C:\composer\vendor/phpcompatibility/phpcompatibility-paragonie,C:\composer\vendor/phpcompatibility/phpcompatibility-wp,C:\composer\vendor/wp-coding-standards/wpcs,C:\Users\Administrateur\Documents\PLUGINS DEV\PilotIn-Coding-Standards\PilotIn
- Set the default standard as PilotIn using:
phpcs --config-set default_standard PilotIn
- Restart your terminal to be sure everything is up to date & try this command to see if everything is set:
phpcs -i
(You should have "PilotIn" showing & you're good to go π)
- Install
wongjn.php-sniffer
extension (VS Marketplace) - Add this to your vscode settings json (Ctrl + Shift + P > Settings json):
"php.validate.executablePath": "C:/Full/Path/To/php.exe",
"php.validate.run": "onType",
"[php]": {
"editor.defaultFormatter": "wongjn.php-sniffer"
},
"phpSniffer.standard": "PilotIn",
"phpSniffer.executablesFolder": "C:/Full/Path/To/Composer/vendor/bin",
Make sure that your paths (both to php.exe
and to the phpcs
and phpcbf
executables) are correct and absolute. Use the full path every time.
- Go to
Files > Settings > PHP > Quality Tools
- Select your files
- Then go to
Editor > Inspections > PHP > Quality tools > PHP_CodeSniffer validation
and select PilotIn inCoding standard
option. You can also choose what type of warning it'll trigger