Table of contents
- Installation of the NetBeans IDE plugin phpcsmd
- Configuration of the NetBeans IDE plugin phpcsmd
- phpMD / PHP CodeSniffer Netbeans Plugin
- Netbeans PHP Editor Extensions (latest fork)
In this article I demonstrate the installation, configuration and usage of the NetBeans IDE plugin phpcsmd. Both version 7.1.2 and version 7.2 (build 201204181547) of NetBeans IDE are used in this tutorial.
Install PHP_CodeSniffer, PHPMD, PHP_Depend and PHPCPD. The preferred way is the installation with the PEAR installer (You have to run these commands as
root on *nix, respectively
Administrator on Windows systems).
pear config-set auto_discover 1 pear install --alldeps pear/PHP_CodeSniffer pear install --alldeps phpmd/PHP_PMD pear install --alldeps pdepend/PHP_Depend pear install --alldeps phpunit/phpcpd pear config-set auto_discover 0
- Start NetBeans IDE 7.x.
- Select Tools > Plugins from the menu bar. The Plugins dialog appears.
- Select the Settings tab.
- Make sure that Plugin Portal is listed in the Update Center. If it is already in the list, proceed with step 6.
Add Plugin Portal to the Update Center.
- Click on the button Add. The Update Center Customizer dialog appears.
- Make sure that the Check for updates automatically checkbox is enabled.
Plugin Portalin the Name input text field and
http://plugins.netbeans.org/nbpluginportal/updates/7.1/catalog.xml.gzin the URL input text field.
- Select the Available Plugins tab.
phpcsmdinto the Search input text field. Click on the Reload Catalog button if it does not appear in the list.
- Enable the Install checkbox in the first column of the list.
- Click on the Install button. The Welcome to the NetBeans IDE Plugin Installer dialog appears.
- Click on the Next > button. The License Agreement dialog appears.
- Enable the I accept the terms in all of the license agreements. checkbox. Click on the Install button. The installation progress starts.
- The Verify Certificate dialog appears. Click on the Continue button. The installation progress continues.
- The Restart NetBeans IDE to complete installation. dialog appears. Enable the Restart IDE Now checkbox. Click on the Finish button. NetBeans IDE is restarted.
After this procedure the NetBeans IDE plugin phpcsmd is installed and can be configured.
- Select Tools > Options from the menu bar.
- Select the item PHP in the Options dialog. After that, select the tab PHPCSMD.
Fill in the following data:
- Enable the checkbox try threading analysis.
- Enable the checkbox update on save.
- Enable the checkbox show notification icon.
- Enable the checkbox PHPCS.
- Enable the checkbox PHPCS.
- Enter the filepath of the PHP_CodeSniffer executable (
phpcs.batunder Microsoft Windows operating systems) in the Script location text input field.
- Enter the coding standard into the –standard= text input field. PHP_CodeSniffer version 1.3.3 has the following coding standards installed:
- Enable the checkbox show Warnings.
- Enable the checkbox Extras.
- Enable the checkbox Unreachable Code (Squiz standard must be installed).
- Enable the checkbox PHPMD.
- Enter the filepath of the PHPMD executable (
phpmd.batunder Microsoft Windows operating systems) in the Script location text input field.
- Enable the checkbox strict.
- Enable the checkbox PHPCPD.
- Enter the filepath of the PHPCPD executable (
phpcpd.batunder Microsoft Windows operating systems) in the Script location text input field.
- Enable the checkbox PDepend.
- Enter the filepath of the PHP_Depend executable (
pdepend.batunder Microsoft Windows operating systems) in the Script location text input field.
- Enable the checkbox Use tabs to organize PdependReport.
- Enable the checkbox Create JDepend statistics.
- Click on in the OK button.
After this procedure the NetBeans IDE plugin phpcsmd is configured and can be used.
- Select Window > Action Items (Window > Tasks for NetBeans IDE versions < 7.2) from the menu bar.
Click on the Filter button and select Edit… from the list.
- Click on the New button.
PHPinto the Name text input field.
- Activate the checkboxes
TODOin the list of the Types tab.
- Click on the OK button.
Every file is checked after it is saved. All coding violations for the current file appear within the Window > Action Items (Window > Tasks) window.
In addition, there is one new annotation for each violation within the Editor window. If there are multiple annotations for one line, one can click on them to cycle through them.
Another nice feature is called violation scan report. Such a report can be generated by right-clicking on a directory within the Project window and select Scan for violations from the context menu (or select Tools > Scan scan for violations from the menu bar). A new window appears. Enable the full checkbox and click on the Rescan button. A list is populated which contains all files of the selected directory and displays the number of violations detected by each static code analyses tool.
Last but not least, there is a new icon in the status bar which displays the violation count for the current file.
Notice: Selecting Window > ScanReport from the menu bar does not seem to trigger any action.
- Right-click on a directory or file within the Project window and select Scan with Pdepend from the context menu (or select Tools > Scan with Pdepend from the menu bar). A new window appears.
- Click on the Scan button in the new window. Six new tabs appear within the previously created window.
- Different Metrics
- JDepend Graph
Notice: Selecting Window > PdependReport from the menu bar does not seem to trigger any action.
Even if it is in an early state, phpcsmd is by now the best NetBeans IDE plugin which is related to static code analyses in the PHP scripting language. All other plugins I tried so far, threw unhandled Exceptions after using them for a while. In addition, phpcsmd supports more external tools for static code analyses.
I hope you enjoyed this article. Leave me a comment or send me a mail for corrections or additions related to this topic.