PHPCheckstyle is an open-source tool that helps PHP programmers adhere to certain coding conventions. The tools checks the input PHP source code and reports any deviations from the coding convention.
The tool uses the PEAR Coding Standards as the default coding convention. But it allows you to configure it to suit your coding standards. The configuration file is a simple to understand xml file explained in the Configuration section.
Unzip the distribution.
unzip phpcheckstyle.zip
The configuration file used by default is config/default.xml.
The user can customize this to suit it to specific coding convention by creating a new configuration file and commenting/uncommenting some tests.
To change the configuration file used, use the --config flag of the command line.
Note : The php.ini used in CLI (Command Line Interface) may be different than the php.ini used by your web server. If the "short_open_tag" param is "Off" in the php.ini, the PHP tokenizer will not correctly return the tokens inside short tags.
Change directory to the PHPCheckstyle installation directory.
cd phpcheckstyle
Execute the run.php script providing the --src option.
php run.php --src "php source directory/file"
Execute the run.php script without any options or with the --help option to see the supported command line options.
$> php run.php --help Usage: php/run.php <options> Options: --src Root of the source directory tree or a file. --exclude [Optional] A directory or file that needs to be excluded. --format [Optional] Output format (html/text/console). Defaults to 'html'. --outdir [Optional] Report Directory. Defaults to './style-report'. --config [Optional] The name of the config file. --debug [Optional] Add some debug logs (warning, very verbose). --linecount [Optional] Generate a report on the number of lines of code (JavaNCSS format) --help Display this usage information.
See Using PHPCheckstyle with ANT.
See Using PHPCheckstyle with Eclipse.
See Using PHPCheckstyle with NetBeans.
See Using PHPCheckstyle with Hudson / Jenkins.
If PHPCheckstyle is located on the same web server as the code that you want to check, you can call directly the "index.php" page and use your browser to launch the analysis.
By adding the "--linecount" option to the command line, PHPCheckstyle will generate an XML file compatible with the JavaNCSS format
This could be used with the JavaNCSS plugin of Hudson.
Warnings can be removed with the help of annotations on a function level or a class level.
To remove a warning add the annotation "@SuppressWarnings warningName" in the PHPDoc where warningName is the identifier of the check rule.
The identifier of the rule is displayed as a tooltip in the generated HTML report.
/** * This is a data objet without getter or setter. * * @package classes * @SuppressWarnings checkUnusedVariables */ class MyDataObject { /** * This property is not used in the class and would have raised a warning. */ var $myProperty; }
Wiki: UsingWithANT
Wiki: UsingWithEclipse
Wiki: UsingWithJenkins
Wiki: UsingWithNetBeans