Menu

coding standards for Joomla in EclipseAt the times when we at Digital Peak where a one man show I didn't care about coding standards. I had my formatter in Eclipse and all was fine. As we are more developers nowadays we needed some rules the code formatting has to follow, otherwise it will be hard for others to read and maintain it. So we decided to adopt to the Joomla coding standards (which was a hard decision for me as I'm an advocate of the Java coding standard) for our Joomla extensions. I'm an Eclipse lover since the early days of Eclipse (was coding my own Eclipse plugins) so I faced the challenge to integrate the PHP codesniffer into the Eclipse IDE. To safe you time, I'm writing down here the steps to accomplish this task.

This should work on windows and linux.

Create your own fork on Github

We at Digital Peak had to adapt some sniffs, because we didn't need so strict rules like Joomla has, so we created our own fork. This means we are able to merge future changes of the Joomla code style and at the same time we can add/modify/remove our own rules. How you can fork a github repository could be found on the web and we do not cover it here again.

As a last step checkout the project somewhere into you file system or even better into your workspace as a repository in eGit.

git clone https://github.com/Digital-Peak/coding-standards.git Joomla

Install the Codesniffer plugins in Eclipse

The code sniffer plugins are maintained by an external project and do not come built in with the PDT plugins. How you can install the plugins can be found here. Install the whole stack and restart Eclipse. Make sure PHP executable is installed too, on windows you have to download it manually and on ubuntu run

apt-get install php5

Configure the Codesniffer

In the project properties (Project->Properties->PHP Tools->PHP CodeSniffer) add your code sniffer standard. After you click ok Eclipse asks you to build the project, click on yes.

coding standard install snifs

I suggest that you enable print PHP output to console and set Tab width to 0 (otherwise the code sniffer will convert the tabs to spaces).

Update code sniffer

If you are using the coding standards from Joomla as reference you need to update the codesniffer version to at least version 1.4.4, otherwise it will fail (thanks to the PHP console output I figured it out).

  1. Download it from here and extract the archive to your file system.
  2. Copy the file CodeSniffer.php and the folder CodeSniffer to {{eclipse-root}}/plugins/org.phpsrc.eclipse.pti.library.pear_1.2.2.R20120127000000/php/library/PEAR/PHP

Formater

If you are a lazy developer as I am you should know the key combination Ctrl+Sift+F. It formats the file according to a rule set from a formatter in your Eclipse preferences (Project->Properties->PHP->Code Style->Formatter). You can find a working formatter on our repository as the one in the Joomla project is broken on Eclipse Kepler. The install screen will then look like

coding standard install formatter

 

 

We use cookies on our website. Some of them are essential for the operation of the site, while others help us to improve this site and the user experience (tracking cookies). You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.