Applying zend coding standard (Netbeans + PHPMD + CodeSniffer)
In this post I'd like to describe how to integrate CodeSniffer and PHPMD with Netbeans.
1. We should install PEAR, running this line is enough
apt-get install php-pear
2. Install PHPMD dependencies (PHPMD works without that dependencies, but it's recommended to have them.)
apt-get install libmagickwand-dev
apt-get install imagemagick
pecl install imagick
apt-get install php5-imagick
3. Install PHPMD
pear channel-discover pear.phpmd.org
pear channel-discover pear.pdepend.org
pear install --alldeps phpmd/PHP_PMD
4. Install CodeSniffer
pear install PHP_CodeSniffer
5. Install phpMD / PHP CodeSniffer Netbeans Plug from http://sourceforge.net/projects/phpmdnb/. Download the *.nbm for you netbeans version (In my case I'm using with 6.9.1)
6. Open netbeans. Go to Tools->Plugins. Go to the "Downloaded" tab, click in add plugins and browse your *.nbm.
7. When you see the plugin in the list, click in install, follow the wizard steps and after finishing it, close the window.
Now you have the plugin installed, it's time to configure it.
8. In netbeans, go to tools->Options. Go to "PHP" selection and look for the phpMD tab.
9. At that point you have all the configuration. My recommendation about important items here:
phpMD batch file: This is the path to your binary file. If you use ubuntu is /usr/bin/phpmd
ruleset filenames: The filename of the rulesets which you want to apply. If you want to use all the default rule sets, put "naming,design,codesize,unusedcode"
10. Click in "test settings", to check if it's working. If it's not maybe the path of the binary is incorrect.
11. Click in "reset cached data" (Actually I don't know what to do this, but if you don't click it, the plugin doesn't work)
12. Go to phpCodeSniffer tab.
13. Here you have all the configuration. This are the important items:
phpCodeSniffer batch file: This is the path to your binary file. If you use ubuntu is /usr/bin/phpcs
standard: Is the coding standard that you want to follow, in Summa Solutions we use Zend Standards so we put "ZEND"
14. Repeat the steps 10 and 11 but in this tab.
15. Close the options window. Go to the Tasks window. Do a right click and click in Filter->Edit.
16. Check "PHP CS Tasks" and "PHP MD Tasks"
17. Close the window and refresh the tasks.
And that is all. If is not working check flushing the caches again.
Note: If you want to use the zend coding standard you need to change one configuration in PHPMD. Go to the file /usr/share/php/data/PHP_PMD/resources/rulesets/codesize.xml and change the line 347
<property name="maxmethods" description="The method count reporting threshold " value="10"/>
<property name="maxmethods" description="The method count reporting threshold " value="50"/>
The others configurations are okey.