Last updated February 24, 2013. Created by das-peter on January 28, 2012.
Edited by balintk, klausi, Matt V., mparker17. Log in to edit this page.
Note: PHP_CodeSniffer version 1.4.1 or higher is required to run Coder Sniffer.
Installing on Unix/Linux/Mac
You will need to install the PEAR package named PHP_CodeSniffer in order to use Coder Sniffer:
- Ensure your PEAR channel list is up-to-date:
sudo pear update-channels - Install PHP_CodeSniffer:
sudo pear install PHP_CodeSniffer
(if you do not have access to PEAR, you will need to download the PHP_CodeSniffer project and install it manually)
Now, install Coder Sniffer:
- Download 7.x-2.x branch of Coder. Ideally, put it outside your webroot.
- Add the Drupal coding standards definitions included with Coder to PHP_CodeSniffer's standards library:
sudo ln -sv /path/to/coder/coder_sniffer/Drupal $(pear config-get php_dir)/PHP/CodeSniffer/Standards/Drupal
If you don't have root access, or just don't want to install Coder Sniffer system-wide, you can always point to the ruleset.xml file directly.
eg.: For convenience, run this in your shell (or add it to ~/.bashrc):alias codercs='phpcs --standard=/path/to/local/coder/coder_sniffer/Drupal/ruleset.xml --extensions=php,module,inc,install,test,profile,theme'
Installing on Windows/XAMPP
- Open the command line.
- Go to your xampp root folder, and from there to: \php\PEAR
- Enter: pear install PHP_CodeSniffer
- Go to: http://drupal.org/project/coder, download the project directly to \php\PEAR\PHP\CodeSniffer\Standards, and extract it, (your directory should be structured so: \php\PEAR\PHP\CodeSniffer\Standards\Drupal)
- You may need to add the following to your path variables: \php to run the command next from any location on your pc.
Using with Drush
While Coder sniffer can be used as a standalone set of rules for PHP_CodeSniffer, drush command support is included to facilitate ease of use, installation, and leveraging of drush features such as site aliasing.
Extract the contents of the coder project into one of the locations specified in the drush README.txt COMMANDS section, including:
- In a subdirectory of the .drush folder in your home directory, like
~/.drush/coder(you may have to create the .drush folder yourself) - In a folder specified with the
--includeoption (seedrush topic docs-configuration) - In
/path/to/drush/commands(not recommended)
Example:
mkdir ~/.drush
cd ~/.drush
drush dl coder-7.x-2.x-devAdd the Drupal coding standards definitions included with Drupal Code Sniffer to PHP_CodeSniffer's standards library
sudo ln -sv /path/to/coder/coder_sniffer/Drupal $(pear config-get php_dir)/PHP/CodeSniffer/Standards/DrupalFor more information about drush, see http://drupal.org/project/drush
Comments
Drupalcs pre-commit hook
There is a sandbox project here: http://drupal.org/sandbox/bevan.wishart/1441638 which contains two pre-commit hooks.
One of which calls drupalcs, just place both those files in .git/hooks and git will check the code against the drupal coding standards on commit.
Replaced by
Replaced by http://drupal.org/project/git_hooks
http://goo.gl/icjPn
DCQ
http://drupal.org/project/git_hooks is deprecated, I continue develop in new project. Now it works like module for drupal and it is more comfortable to use.
You can check drupal code style on your project automatically with this module http://drupal.org/project/dcq for team development through git.
Resolve installation error
After following all the above steps correctly when I run
drupalcs abc.module, it gives following error:When I changed the drupalcs alias to this:
its working fine
Regards,
Subhojit Paul
Web Developer @ Innoraft Solutions
Flawed documentation
Current documentation claims that the symlink should be created to /path/to/coder/coder_sniffer/Drupal although there is no coder_sniffer subfolder in Coder package(s).
no coder_sniffer subfolder in Coder package(s).
there is no coder_sniffer subfolder in Coder package(s).
help!
Have you tried the 2.x
Have you tried the 2.x branch?
Perhaps this is one of the
Perhaps this is one of the PHP_CodeSniffer issues for folks with sites that aren't Drupal 7. The drupalcs project is defunct and the coder project doesn't provide an option for integration with the PHP_CodeSniffer at the moment. Would be nice to have that in the documentation on the coder page.