Menu

[r13]: / wiki / Documentation.wiki  Maximize  Restore  History

Download this file

107 lines (78 with data), 5.5 kB

#summary PHPCheckstyle documentation
#labels Featured

= Overview =

Spike 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 [http://pear.php.net/manual/en/standards.php 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.

== Requirements ==
 * PHP 5.0 or newer. XSL extension needs to be enabled. It is enabled by providing the --with-xsl=[libxslt-install-dir] to the configure line.
 * Linux, Windows.
 * Web browser to view the checkstyle report (for html format only).

== Installation ==

Make sure the requirements above are matched (PHP XSL extension needs to be enabled).

* Unzip the distribution.
{{{
unzip phpcheckstyle.zip
}}}

This will create a directory called phpcheckstyle and expand all files in it.

== Running PHPCheckstyle ==
 * 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"
}}}

=== Command line Options ===

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

  * --src: Specifies the php source file. Or a directory under which the php source files reside. If a directory is specified then all the php files within that directory will be processed (unless the a file or subdirectory is in the --exclude list)
  * --exclude: Excludes the specified file or directory from processing. Specify multiple times for more than one file/directory
  * --outdir: The directory where the checkstyle report is to be stored. The default is ./style-report.
  * --format: Either "html", "text" or "console". Default is "html". The report is generated in the file outdir/index.html in case of "html" format or outdir/style-report.txt in case of "text" format. The "console" mode can be used to interact with tools that analyse the output of the console like the DLTK tools of Eclipse.
  * --config: Allow to specify the name of the configuration file used. The config file must be placed in the "config" directory.
  * --debug: Generates some debug information about the code analysed (it shows the tokens found, this is very verbose).
  * --linecount: Generates a new XML file in the JavaNCSS format that will contain informations about the number of classes, functions, lines of code and lines of comment of the analysed project.

== Configuration ==
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.

== Using PHPCheckstyle with Eclipse ==

Eclipse is already able to do some checks and to reformat your code (CTRL + SHIFT 9+ F) with [http://www.eclipse.org/pdt/ PDT].

It is also possible to add some extenal tools like PHPCodeSniffer or PHPCheckstyle to verify the code you're editing.

  * First, install the Eclispe PHP Tool Integration (see http://www.phpsrc.org/wiki/)

Eclipse Update URL : http://www.phpsrc.org/eclipse/pti/

  * Get last version of PHP Checkstyle.
  * In Eclipse, configure a new validator :
   * Preferences->Dynamic Languages->Validators
   * Click "Add..."
   * Select the "External PHP Script" type
   * Set the Path to the PHP Checkstyle "run.php" file.
   * Configure the PHP Executable to match your environment.
  * Add some arguments to the executable
{{{
--src %f --config "default.cfg.xml" --format console
}}}
  * Add some pattern rules to read the result:
   * %f INFO Line:%n - %m Warning
   * %f WARNING Line:%n - %m Warning
   * %f ERROR Line:%n - %m Error

And it should be OK, on your PHP Editor, right click, select "DLTK Validators" and the script should run.

== Using PHPCheckstyle with Hudson ==

The XML generated by PHPCheckstyle is compatible with the original [http://checkstyle.sourceforge.net/ Checkstyle] XML format.

The [http://wiki.hudson-ci.org/display/HUDSON/Violations Violation plugin] of [http://hudson-ci.org/ Hudson] is capable of reading this file and displaying and historising the results.

== Counting the lines of code of a project ==
By adding the "--linecount" option to the command line, PHPCheckstyle will generate an XML file compatible with the [http://kclee.de/clemens/java/javancss/ JavaNCSS] format

This could be used with the [http://wiki.hudson-ci.org/pages/viewpage.action?pageId=36603031 JavaNCSS plugin] of Hudson.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.