Tried PHP Mess Detector on WordPress

So first I had to install PDepend, PHPMD depends on it.

sudo pear channel-discover pear.pdepend.org
sudo pear install pdepend/PHP_Depend

pear channel-discover pear.phpmd.org
sudo pear install phpmd/PHP_PMD

Help text for PHPMD:

Mandatory arguments:
1) A php source code filename or directory. Can be a comma-separated string
2) A report format
3) A ruleset filename or a comma-separated string of rulesetfilenames

Available formats: xml, text, html.
Available rulesets: cleancode, codesize, controversial, design, naming, unusedcode.

Optional arguments that may be put after the mandatory arguments:
--minimumpriority: rule priority threshold; rules with lower priority than this will not be used
--reportfile: send report output to a file; default to STDOUT
--suffixes: comma-separated string of valid source code filename extensions
--exclude: comma-separated string of patterns that are used to ignore directories
--strict: also report those nodes with a @SuppressWarnings annotation

Running phpmd:

mike@mike:~/Sites/wordpress-svn$ time phpmd . text codesize,unusedcode > phpmd.log

real    29m3.751s
user    28m30.463s
sys     0m12.998s

Output is available at http://pastebin.com/BST2evre

Static code analysis

After creating the #28855 ticket for WordPress Core I thought about making some BASH scripts to grep this kind of lines. For example: find PROJECT_DIR -iname "*.php" -exec php -l {} \; After some reading and googling I ended up reading Static analysis tools for PHP. I’m now just a WordPress newcomer, but read and heard a lot about WP’s code that it’s ugly or not “good” as some professional developers mention, OK they might be right, don’t care, WP is awesome and millions are using it, but this is another story. I like the WP community and the whole ecosystem, that’s why I care about it. This static code analysis could be beneficial for the WP and also other codebases. I know that IDE’s have such functionality, but some of these warnings are displayed via some small icons and we are human and can overlook these, but the software shouldn’t suffer from this. There are also devs who don’t use IDE’s as me, but rather for example stick with VIM, because of its awesome text movements. The above mentioned article mentioned PHP Analyzer that links to a commercial version of it so I tried the trial version on a forked WP GitHub repo. Screen Shot 2014-07-12 at 8.36.24 PM Screen Shot 2014-07-12 at 10.38.08 PM Screen Shot 2014-07-12 at 10.38.26 PM Screen Shot 2014-07-12 at 10.43.06 PMScreen Shot 2014-07-13 at 9.55.29 AM

 

The next day I found PHP analyzer on sourceforge which is outdated, but on https://github.com/scrutinizer-ci/php-analyzer/tree/legacy is an updated version. Christopher alse describes how does he use Grunt for PHP. Many thanks Chris for the posts 😉
UPDATE: My good friend suggested looking at http://www.sonarqube.org/