PHP Code Sniffer breaks apart in tokens PHP, JavaScript and CSS files and detect violation of coding standards.
Let’s start with Installation step and then Netbeans configuration
(tested only on Ubuntu)
sudo pear install --alldeps php_codesniffer
brew install php-code-sniffer
You can install brew by going to http://brew.sh/
TODO
Run following command to check available coding standards by default.
phpcs -i
You will get something like:
The installed coding standards are MySource, PEAR, PHPCS, PSR1, PSR2, Squiz and Zend
You can also find them in filesystem:
cd $(pear config-get php_dir)/PHP/CodeSniffer/Standards/
We are following these WordPress coding standard – https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards
You can install it using:
git clone git://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git $(pear config-get php_dir)/PHP/CodeSniffer/Standards/WordPress
Note: Instructions given below are for NetBeans 7.4+. If you are using older version, please upgrade NetBeans.
Go to Netbeans Tools > Options > PHP
If all goes well you will see something like below in your netbeans output window:
We are using Netbeans 7.4 beta which has “Code Analysis” built in.
For old Net Beans version you can install it from Tools > Plugins
.
Just go to “Available Plugins” tab and search for “phpcs”. You will get 2 options. Try both! Or better upgrade to Netbeans 7.4.
This should have been cakewalk. But if you are on mac and using brew it might get tough.
In any case if NetBeans refuse to show you CodeSniffer standards in drop-down menu, please run following:
pear config-show | grep bin_dir
It outputs
PEAR executables directory bin_dir /usr/local/Cellar/php54/5.4.19/bin
Just append phpcs
to it so it becomes /usr/local/Cellar/php54/5.4.19/bin/phpcs
Also, you need to use php binary path by brew:
Select a file or a folder. Then click Source >> Inspect
Menu.
Then select Code Sniffer configuration from drop-down and hit “Inspect” button.
rtCamp uses GitLab and GitLab-CI to manage its product line.
Installation process will be similar to installing on Linux (assuming you are using Linux to run GItLab-CI Runner).
If you are rtCamper using ci.rtcamp.com, then you can ignore this part as all runners have CodeSniffer already installed.
Go to GitLab-CI Project Settings and paste following line in “Scripts” section.
phpcs "--standard=WordPress" "--report=full" "--extensions=inc,php,phpt,php4,php5,php3,phtml" "--encoding=UTF-8"
Screenshot:
Comments
in case pear: command not found :
Try this : sudo apt-get install php-pear