Install and test php_codesniffer on ubuntu

You are here

testing phpcs example

The PHP code sniffer is used to test the php code inside a php file to see if it meets the PRS-0 coding standard by default. It will test the following code types PHP, JavaScript and CSS. You can test any file from the command line.  Here is an example on installing and testing a file in Ubuntu.

Install PHP sniffer

Install the the PHP sniffer library using PRS-0 installation tool from the command line. Make sure that you have the root privileges (sudo) to install the new package

~$ sudo pear install PHP_CodeSniffer

terminal install code_sniffer

 

Testing PHP sniffer

Then navigate to the directory that you want to test the class against. I have created a class with a lot of errors so that they show when we do a test.

~$ phpcs HumanClass.php 

These are the results that I got from the phpcs command. I have also added two files, one that has the errors and one that passed all the tests so you can use the classes to trial the command.

testing phpcs example

 

AttachmentSize
929 bytes