CodeSniffer, an essential development tool that ensures your code remains clean and consistent, should always be with you while writing code to check and fix the messy things. For those people who use NetBeans IDE to write PHP applications, here are the steps to integrate PHP CodeSniffer with NetBeans IDE.
- Open NetBeans IDE. ( Let me tell you, I am using NetBeans IDE 7.3 for this demo )
- Install the NetBeans plugin ‘phpCS-MD’ by going to Tools -> Plugins screen.
Click on the “Available Plugins” tab and search for ‘phpCS’ in the search box provided on top-right corner. Click and check the plugin and click on the “Install” button.
- Once installed, lets configure it.
Go to “Tools” -> “Options”.
- Click on the tab “CodeSniffer”.
Here you have to provide the path to phpcs.bat file present under your PHP installation directory. Do this by clicking the “Change” button there.
- Click on the “Test Settings” button and if it shows the PHP CodeSniffer version details, then its configured successfully.
Now, click OK and go back to your code for checking against a particular coding standard. If you want to set a different coding standard definition, then setup that standard before hand on CodeSniffer. How to do that ? Follow my previous post to know how to install CodeSniffer and various Coding Standard definitions. Go to the CodeSniffer setting tab on NetBeans and set the Coding Standard definition name there in the input box named “Standard”.
On the code screen, you can see a new button with a single Blue Eye on the tool bar. This is to check any file for code issues. Click on that and you can see a new section comes below your code named “PHP CS/MD” and displays all the problems in the code row-wise. Now fix the messy code. Happy Coding 🙂