Proposal for "PHP_CodeSniffer"

» Metadata » Status
» Description
PHP_CodeSniffer is a PHP5 script that tokenises PHP code and detects violations of a defined set of coding standards. It is an essential development tool that ensures that your code remains clean and consistent. PHP_CodeSniffer "sniffs" PHP code and detects any code that violates your coding standards. It can even help prevent some common semantic errors made by developers.

PHP_CodeSniffer comes with a default set of coding standards, the PEAR coding standards. We've done our best to try and convert the PEAR coding standards document to a set of code sniffs, but more testing is required and any help would be appreciated.

Useful links for information are:

  1. Download/Installation instructions
  2. Usage instructions
  3. FAQ


If you receive errors while checking your source code, it is probably the result of a problem within PHP_CodeSniffer that is stopping the correct tokenising and parsing of that piece of code. If you can, please provide the piece of code that is causing the problem so that we can fix it easily. It is often quite hard to reproduce the same error without using code with the same structure.
» Dependencies » Links
  • PHP >= 5.1.0
» Timeline » Changelog
  • First Draft: 2006-07-19
  • Proposal: 2006-07-19
  • Call for Votes: 2006-08-28
  • Greg Sherwood
    [2006-07-25 05:11 UTC]

    Version 0.0.2 released:
    - Removed the including of checked files to stop errors caused by parsing them
    - Removed the use of reflection so checked files do not have to be included
    - Memory usage has been greatly reduced
    - Much faster tokenising and checking times
    - Reworked the PEAR coding standard sniffs (much faster now)
    - Fix some bugs with the PEAR scope indentation standard
    - Better checking for installed coding standards
    - Can now accept multiple files and dirs on the command line
    - Added an option to list installed coding standards
    - Added an option to print a summary report (number of errors and warnings shown for each file)
    - Added an option to hide warnings from reports
    - Added an option to print verbose output (so you know what is going on)
    - Reordered command line args to put switches first (although order is not enforced)
    - Switches can now be specified together (eg. php -nv) as well as separately (phpcs -n -v)

    I've also updated the usage docs on the package website so you can see more of PHP_CodeSniffer without having to install it (if you don't want to).
  • Greg Sherwood
    [2006-08-22 02:09 UTC]

    Version 0.0.3 released:
    - Added sniff to check for invalid class and interface names
    - Added sniff to check for invalid function and method names
    - Added sniff to warn if line is greater than 85 characters
    - Added sniff to check that function calls are in the correct format
    - Fixed error where comments were not allowed on the same line as a control structure declaration
    - Fixed error where printing error report with warnings hidden showed blank reports
    - Added command line arg to print current version (--version)
  • Greg Sherwood
    [2006-08-28 06:18 UTC]

    Version 0.0.4 released:
    - Added .bat file for easier running of PHP_CodeSniffer on Windows
    - Sniff that checks method names now works for PHP4 style code where there is no scope keyword
    - Sniff that checks method names now works for PHP4 style constructors
    - Sniff that checks method names no longer incorrectly reports error with magic methods
    - Sniff that checks method names now reports errors with non-magic methods prefixed with __
    - Sniff that checks for constant names no longer incorrectly reports errors with heredoc strings
    - Sniff that checks for constant names no longer incorrectly reports errors with created objects
    - Sniff that checks indentation no longer incorrectly reports errors with heredoc strings
    - Sniff that checks indentation now correctly reports errors with improperly indented multi-line strings
    - Sniff that checks function declarations now checks for spaces before and after an equals sign for default values
    - Sniff that checks function declarations no longer incorrectly reports errors with multi-line declarations
    - Sniff that checks included code no longer incorrectly reports errors when return value is used conditionally
    - Sniff that checks opening brace of function no longer incorrectly reports errors with multi-line declarations
    - Sniff that checks spacing after commas in function calls no longer reports too many errors for some code
    - Sniff that checks control structure declarations now gives more descriptive error message