PHP_CodeSniffer is a PHP script that tokenizes PHP files to detect violations of a defined coding standard. It is an essential development tool that ensures your code remains clean and consistent. It can also help prevent some common semantic errors made by developers.
This is a custom PHP_CodeSniffer standard for Bigbank, based on and compatible with PSR-2.
Usage by IDE-s or manually from the CLI.
- Clone the repository
- Install Composer dependencies:
composer install
You should now be able to run phpcs
from the command line:
$ vendor/bin/phpcs --standard=src/CodeSniffer/Standards/Bigbank <target-file>
- Set the path to the
phpcs
executable: File -> Settings -> PHP -> Code Sniffer. Set it to<this-repo>/vendor/bin/phpcs
- Activate the
phpcs
inspection (per project): File -> Settings -> Inspections -> PHP -> PHP Code Sniffer validation. Tick the checkbox to activate the inspection. Set the coding standard as Custom and select the standard directory:<this-repo>/src/CodeSniffer/Standards/Bigbank
.
PhpStorm will now automatically inspect your code and highlight the lines where errors are found. You can also run inspections on custom scopes by using Code -> Inspect Code.
Usage by automated tools such as Travis or Bamboo.
- Require
bigbank/phpcs
in yourcomposer.json
require-dev
section - Configure the CI server to run
phpcs
as part of its static analysis
You can manually mark parts of the code as ignored by phpcs with annotations.
@codingStandardsIgnoreStart
@codingStandardsIgnoreEnd
@codingStandardsIgnoreFile
- marks the entire file as ignored
It is possible to fix some errors (for example, no empty line at the end of the file) automatically, in bulk (for dozens of files). For more, read Fixing Errors Automatically.
Please see CHANGELOG for more information what has changed recently.
PHP_CodeSniffer is developed and owned by Squiz Labs. This custom standard is licensed under the Apache 2.0 License (Apache-2.0). Please see License File for more information.