Coding guidelines or How to stick to them

Thanks to Seb and his new phpcs project we now have a tool which helps us to keep an eye on the coding standards. Simply said this is a set of rules for the PEAR pacakge PHP_CodeSniffer. Some docs about how to install and configure it can be found in the wiki at http://code.zikula.org/phpcs.

Gabriel, Axel and I installed and tested it and adjusted the docs to reflect our experiences.


As a first step we will run these tests locally and correct the 2.0.0-
codebase step by step (not 1.x!) . Axel started with the includes folder yesterday, Gabriel will have a look at the modules folder and I
started with the files in the Zikula root and continue with the system
folder, there is more to come and any help here is appreciated.

Once we got through the code we will install this ruleset as a pre-
commit-hook in the cores svn repository. This means that any commit
that violates the rules will be rejected!

Right now the rules we are using are

* correct line endings: This should be unix-style LF, not CR/LF like
Windows (DOS...) uses it. Our linux friends usually don't care about
it, but all we others should. How to solve conflicts: Use a tool like
dos2unix before commtting and set the svn property svn:eol-style to LF
(upper case is important here!) instead of native. This tells
subversion to convert everything to LF upon commit.

* correct php docs headers, see http://code.zikula.org/core/wiki/development/codingstandards for more information about this. Please have a special look at the specifications for @category, @package and @subpackage!

* correct placement of opening curly brackets ({): on a new line for functions, on the same line in a conditional statement.

* no tabs, but spaces (in our case 4, in words four) for indenting the code.

Once the codebase is cleaned we will add more and more rules. This should help us to keep the code clean and maintainable.

Share This | Print

Trackbacks

(The URL to TrackBack this entry is: http://blog.zikula.org/index.php?module=TrackBack&id=26,1-25). If your blog does not support Trackbacks you can manually add your trackback by using this form.

Comments

Comment by:
mumuri's Avatar
mumuri
11 Jan 2009 - 08:11PM
php checkstyle :)
Perhaps this can help, i only know the Java version ph eclipse checkstyle which is quite well.

----------------------------------------
Spike PHPCheckstyle is an open-source tool that helps PHP programmers adhere to certain coding conventions. The tools checks the input PHP source code and reports any deviations from the coding convention.

The tool uses the PEAR Coding Standards as the default coding convention. But it allows you to configure it to suit your coding standards. The configuration file is a simple to understand xml file explained in the Configuration section.

http://developer.spikesource.com/wiki/index.php/Projects:phpcheckstyleDocs
http://www.unixgarden.com/index.php/programmation/respectez-les-conventions-de-codage-avec-phpcheckstyle-et-php_beautifier
http://developer.spikesource.com/wiki/index.php/Projects:phpcheckstyleDocs
----------------------------------
 

Add a new Comment









 
Close

You don't have permission to e-mail this story - please login