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?
1 Answer
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.
-
Thanks for posting such a clear answer, and for the positive shaming to encourage me to start using a CI server.– jmansMay 15, 2011 at 20:13
-
4Having recently set up all three (and more) on Jenkins for our PHP projects, I can heartily recommend all three tools. Jun 2, 2011 at 1:07
-
1Still the use of pdepend additionally to phpmd is not clear. Phpmd also generates metrics (and has splendid plugin for Jenkins) and can be used real-time in PHPStorm. What would pdepend do for me what I cannot get from phpmd? Dec 23, 2013 at 11:45
-
@AlexanderPalamarchuk well, isn't it obvious from the documentation? pdepend.org/documentation/software-metrics/index.html is quite different from phpmd.org/rules/index.html. Except for NPath and Cylcomatic Complexity, there is little overlap.– GordonDec 23, 2013 at 15:51
-
@Gordon And also things like "Number Of Methods", "Lines Of Code", "Coupling Between Objects" etc. I mean logically these tools seem rather similar. I would correct my opinion that yes, pdepend provides features for package metrics, and it can be considered as a reason to use instead of phpmd. But together it is quite annoying. You have to configure the same parameters in two different products. Besides pdepend cannot be built-in in PhpStorm so it's hard to control its inspections on-fly. So I don't see how to use it in Continuous Integration. Dec 30, 2013 at 16:31