PHP Tool Integration (PHPsrc)
The Web Dev Zone is brought to you in partnership with Mendix. Discover how IT departments looking for ways to keep up with demand for business apps has caused a new breed of developers to surface - the Rapid Application Developer.
In a previous post, I talked about Continuous Integration. If your Continuous Integration server runs on every commits, it will help you keep your code quality high. It will also make integration a non issue.
However, when I make a mistake, produce sub-optimal code or if I write code that does not respect our coding standards I want to know before I commit. I would rather fix my errors before they break the build. I can run all the tools that the server runs. But running them on my machine and analyzing the results every time I save will be painful. Fortunately, there is an easy solution.
PHPsrc is a plugin that allow you to run PHP_CodeSniffer, PHPUnit, PHP Depend and PHP Copy/Paste Detector directly in Eclipse. The site also says that more tools should come. As you work, you will see any transgression you make. That will save you from breaking the build, but it also makes it easier to fix the problem. After all, you just wrote the faulty lines of code.
You install it like any other Eclipse plugin. Go to the Help menu and click on “Install new software…” In the Install dialog, click on “Add…”, choose a name for the repository and enter “http://www.phpsrc.org/eclipse/pti/” in the location. After you click on OK, Eclipse will detect “PHP Tool integration. Select it and click on Next twice. Accept the condition and click on Finish. After the installation is completed, you will have to restart Eclipse.
After the installation, in the preferences you will have a new “PHP Tools” menu. Make sure that every tools have an PHP executable and a PEAR library selected. For PHP CodeSniffer, you will also need to pick a standard.
Your Eclipse should now have new buttons in the toolbar and a new “PHP Tools” sub menu in the PHP Explorer.
PHPsrc will now check your code every time you save. Errors and warnings will be added to the Problems tab and the Type will be the tool that found the problem. The lines that causes problems will also be underlined like a syntax error. The copy paste detector will send the results to the console.
Here’s what Eclipse looks like with PHPsrc:
If you develop PHP code in eclipse, you should definitely give PHPsrc a try. If you use a continuous integration server, being warned about potential issues before you commit to your source control repository can save you from becoming the one who broke the build.