Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP_CodeSniffer, PHPMD or PHP Depend

I am looking at doing some static code analysis of an exisiting PHP project, and I'm having trouble understanding the distinctions between PHP_CodeSniffer, PHPMD, and PHP Depend. Are these simply alternatives to the same problem, or do they complement each other in some ways? Why might a developer choose one over the other?

like image 344
jmans Avatar asked May 15 '11 16:05

jmans


People also ask

What does PHP Code Sniffer do?

PHP Code Sniffer (PHPCS) is a package for syntax checking, available from PEAR. It can check code against defined rules covering anything from whitespace through doc comments to variable naming conventions and beyond.

How do I run PHP CodeSniffer?

In the Settings dialog, go to Editor > Inspections. From the inspections screen, expand the PHP | Quality tools node and enable “PHP CodeSniffer validation”. In the configuration pane that is now enabled, select “Custom” from the “Coding standard” dropdown, locate the ruleset configuration ( phpcs.


1 Answers

Shameless copy from http://phpqatools.org

pdepend

pdepend can generate a large set of software metrics from a given code base. These values can be used to measure the quality of a software project and they help to identify the parts of an application where a code refactoring should be applied.

phpmd

phpmd scans PHP source code and looks for potential problems such as possible bugs, dead code, suboptimal code, and overcomplicated expressions.

phpcs

phpcs tokenises PHP, JavaScript and CSS files and detects violations of a defined set of coding standards. It is an essential development tool that ensures your code remains clean and consistent. It can also help prevent some common semantic errors made by developers.

So no, they are not just alternatives. PDepend and PMD focus on on software metrics while PHPCS defines rules based on patterns in the token stream. PDepend doesnt care the slightest about finding Coding Standard violations. You should use all three of them. If possible in your Continuous Integration server, for instance Jenkins.

like image 195
Gordon Avatar answered Sep 23 '22 09:09

Gordon