Static analysis of a PHP project by a CIP such as Jenkins requires optimization of the rules for excluding directories that are not part of the developed code. In the following article I want to introduce the most common methods and tools addressing static code analysis in PHP.
Static analysis tools
Beside the usual checks like manual code review, training (e.g. using XP programming sessions) and automated unit tests using PHPUnit, there are some metrics that can be measured automatically making my work easier and helping to reduce error rates in the review process.
So, I want indicators that can measure the quality of my code. These indicators are produced by third-party tools (for the most part, it is a port – for the PHP – of analysis tools from the Java world) such as:
- Pdepend for statistics on code quality (complexity cyclomatic, depth of inheritance, number of methods overloaded …). This utility is based on JDepend.
- Phpmd for the detection of certain bugs like unused parameters, methods or properties.
- Phpcpd for duplicate code detection.
- Phploc to quickly measure the size and structure of a PHP project.
- Phpcs for code style check (see also the PEAR package documentation).
- Phpdoc for generating documentation from code comments (similar to Javadoc).
- Phpcb to generate a stylized view of the code with the highlighting of the alerts raised by the previous tools. This generates a site in HTML containing the code of the application.
Read more from original source: Introduction to automated, static code analysis in PHP
References:
- https://www.davd.eu/introduction-to-automated-static-code-analysis-in-php/
- http://benjamin-balet.info/developpement/accelerer-lintegration-continue-dun-projet-php/
- https://github.com/exakat/php-static-analysis-tools
- https://github.com/EdgedesignCZ/phpqa
- http://pear.php.net/manual/en/package.php.php-codesniffer.php
Comments