Skip to content

A custom, PSR-2 compliant coding standard for phpcs

License

Notifications You must be signed in to change notification settings

bigbank-as/phpcs

Repository files navigation

Custom Rule Set For PHP_CodeSniffer

Latest Stable Version on Packagist Software License Total Downloads

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.

Installing

Standalone

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>

PhpStorm Integration

  • 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.

CI Server

Usage by automated tools such as Travis or Bamboo.

  • Require bigbank/phpcs in your composer.json require-dev section
  • Configure the CI server to run phpcs as part of its static analysis

Suppressing Warnings

You can manually mark parts of the code as ignored by phpcs with annotations.

  • @codingStandardsIgnoreStart
  • @codingStandardsIgnoreEnd
  • @codingStandardsIgnoreFile - marks the entire file as ignored

Fixing Errors Automatically

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.

Links

Change log

Please see CHANGELOG for more information what has changed recently.

License

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.

About

A custom, PSR-2 compliant coding standard for phpcs

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages