Accepted standards and style guides
PHP code style specification for CodeSniffer
The code style specification is written for the CodeSniffer PEAR package so make sure you have this package installed on your machine:
sudo pear install PHP_CodeSniffer
Once you have the CodeSniffer installed you should clone this github repository, it does not have to be in a fixed location on your machine:
git clone email@example.com:Hotelsnl/standards.git
Now that all required files have been installed on your machine we need to configure the CodeSniffer so it knows about your standards specification. We assume that CodeSniffer is installed in it's default location, but it might be somewhere else depending on your configuration and for the sake of simplicity we assume that you cloned the github repository from the step above in your home (~) directory:
cd /usr/share/php/PHP/CodeSniffer/Standards/ sudo ln -s ~/standards/Hotelsnl
The symlink is needed as CodeSniffer expects the standard to be in it's own directory.
VIM using the syntastic plugin
The CodeSniffer standard can easily be implemented using the Syntastic plugin for VIM. The installation instructions for this plugin can be found at scrooloose/syntastic
If you have the Syntastic plugin installed you can add the CodeSniffer
configuration for it to your
let g:syntastic_phpcs_conf="--standard=Hotelsnl --tab-width=2"
Note for Debian 6 users
If vim does not automatically show the codingstandards you can add this line to yor .bash_profile
alias phpcs='phpcs --standard=Hotelsnl'
While this IDE is far less superior then VIM, it is also possible to integrate the CodeSniffer with it. There is a extensive installation guide on the Drupal.org site for it.
This IDE comes with a handy plugin and detailed installation guide which can be found on the interwebz
To prevent bad and invalid code from being committed in to the repositories you
need to install the
pre-commit hook from this repository in to the
.git/hooks folder of your project. This needs to be done every time you clone
To install the git hooks you can run the following commands in your terminal:
cd .git/hooks ln -s ~/standards/Hotelsnl/hooks/pre-commit
To ignore the pre-commit hook you can append
--no-verify to the commit command
If there is already pre-commit hook in your project you can append the contents of the pre-commit hook to that file.