All components and tools of the PHP quality assurance toolchain should be installed using the PEAR Installer, the backbone of the PHP Extension and Application Repository that provides a distribution system for PHP packages.
Depending on your OS distribution and/or your PHP environment, you may need to install PEAR or update your existing PEAR installation before you can proceed with the instructions in this chapter.
sudo pear upgrade PEAR
usually suffices to
upgrade an existing PEAR installation.
http://pear.php.net/manual/en/installation.getting.php
explains how to perform a fresh installation of PEAR.
The following two commands are all that is required to install the PHP quality assurance toolchain using the PEAR Installer:
pear config-set auto_discover 1
pear install pear.phpqatools.org/phpqatools PHPDocumentor
After the installation you can find the source files for the installed packages inside your local PEAR directory; the path is usually /usr/lib/php.
Here is an overview of what the tools we just installed are used for:
PHPUnit is the de-facto standard for the unit testing of PHP code.
PHP_CodeSniffer is the most commonly used tool for static analysis of PHP code. It is typically used to detect violations of code formatting standards but also supports software metrics as well as the detection of potential defects.
phpcpd (PHP Copy/Paste Detector) searches for duplicated code in a PHP project.
PHP_Depend is a tool for static code analysis of PHP code that is inspired by JDepend.
phpmd (PHP Mess Detector) allows the definition of rules that operate on the raw data collected by PHP_Depend.
phploc measures the scope of a PHP project by, among other metrics, means of different forms of the Lines of Code (LOC) software metric.
PHP_CodeBrowser is a report generator that takes the XML output of the aforementioned tools as well as the sourcecode of the project as its input.
Although it is currently being replaced by more modern tools such as phpdox, we will use PHPDocumentor for automated API documentation generation for PHP code in this book.
In later chapters we will look at each of these tools individually and see how and why they are useful in a continuous integration setup.