Fishtrap

php and other stuff I know

Silverstripe Code Sniffs for PHP_CodeSniffer

| 3 Comments

image credit Emilie Eagan

By Emilie Eagan (photographer)

I have been working quite a bit with Silverstripe recently. It is a very interesting CMS with a nice programming interface. Compared to CMS’s like Drupal and wordpress, however, the comunity is small and I’ve been doing my bit to help things along. Whith this in mind I have created some PHP_Codesniffer rules for the Silverstripe coding standards. In my opinion there is no point in having coding standards if there is not an automated way of checking adherence to them and php code sniffer the best tool and integrates well with continuos integration environments.

The sniffs are located on github here.

3 Comments

  1. Legend, mate! (as the kiwis would say)

    Keep an eye on our dev mailinglist (http://groups.google.com/group/silverstripe-dev/), I’m preparing a revised draft of the coding standards (basically filling in the gaps, and making them more readable) – will post there soon.

    I’ve got given a set of customized code sniffs for SilverStripe before, but haven’t had a chance to look at them yet. Yours are definetly a good start!

  2. Any tips on getting these to work? I get “coding standard is not installed” even if I install it (phpcs 1.3.0RC1). This is my first attempt at using phpcs in any context, but I noticed that the standard lacks a ruleset.xml file, as compared with the preinstalled standards.

  3. Fred: You will need to make sure that the code is in a directory called Silverstripe in your Standards directory. Not in a directory called Silverstripe-Code-Sniffs. Obviously I couldn’t create a project on github called Silverstripe.

    Heres the output from an install I just did


    nat@ubuntu-10:/usr/share/php/PHP/CodeSniffer$ tree Standards/Silverstripe/
    Standards/Silverstripe/
    ├── SilverstripeCodingStandard.php
    └── Sniffs
    ├── NamingConventions
    │   ├── ValidFunctionNameSniff.php
    │   └── ValidVariableNameSniff.php
    └── WhiteSpace
    └── DisallowFourSpacesSniff.php

Leave a Reply

Required fields are marked *.