Skip to content

Latest commit

 

History

History

CodeSniffer

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Static Code Analysis Toolbox

Installation

  1. Install phpcs:
pear install PHP_CodeSniffer
  1. Find your PEAR directory:
pear config-show | grep php_dir
  1. Copy, symlink or check out this repo to a folder called Symfony2 inside the phpcs Standards directory:
cd /path/to/pear/PHP/CodeSniffer/Standards
git clone git://github.com/opensky/Symfony2-coding-standard.git Symfony2
  1. Do the same for this standard ( Abstrus ).

  2. Set Abstrus as your default coding standard:

phpcs --config-set default_standard Abstrus
  1. Make sure the standard is correctly installed
phpcs -i
  1. Profit!
cd /path/to/my/project
phpcs
phpcs path/to/my/file.php

Integration with your text editor

PhpStorm and IntelliJ

  1. Open the project settings: File -> Settings (on PC) PhpStorm -> Preferences (on mac)

  2. Click Code Sniffer

  3. Enter the the path of the Code Sniffer executable or select it using the lick the Browse button.

  4. Click the Validate button to check if the Code Sniffer is compatible with your editor.

  5. Select your coding standard from the combo box.

  6. Don't check the Ignore warning box !

  7. Joy !

SublimeText

See a good plugin here.

Vim

Using only the phpcs plugin

  1. Download the .vim file from here

  2. Copy it to ~/.vim/plugin

  3. Set the coding standard to follow in your ~/.vimrc :

let g:phpcs_std_list="Abstrus" 
  1. Set the max output line count in your ~/.vimrc :
let g:phpcs_max_output = 0 " Unlimited output. 
" or 
let g:phpcs_max_output = 2000 " Output limited to 2000 line 

Using the phpqa plugin

See the official documentation.

Credits

This doc and standard has mainly been taken from the Symfony2 coding standard