Home > php > PHP CodeSniffer

PHP CodeSniffer


PHP CodeSniffer

PHP_CodeSniffer is a PHP5 script that tokenises and “sniffs” PHP, JavaScript and CSS files to detect violations of a defined coding standard. It is an essential development tool that ensures your code remains clean and consistent. It can also help prevent some common semantic errors made by developers.

Install:
Pear install PHP_CodeSniffer. Please follow these steps.
1. Click on start->run->cmd
2. Go to php directory where php.exe
3. Now, write commond ‘pear install PHP_CodeSniffer’

Start PHP_CodeSniffer like this:
1. Click on start->run->cmd
2. Go to php directory where php.exe. E.g c:\wamp\bin\php\php5.3.0
3. Now write command ‘phpcs –standard= e.g

Scan a directory:
c:\wamp\bin\bin\php\php5.3.0>phpcs –standard=PEAR c:\wamp\www\phptest

Scan a file:
c:\wamp\bin\bin\php\php5.3.0>phpcs –standard=PEAR c:\wamp\www\test.php

Report:
C:\wamp\bin\php\php5.3.0>phpcs –report=xml –report-file=c:\wamp\www\test.xml c
:\wamp\www\codesniffer_test\test.php
http://pear.php.net/manual/en/package.php.php-codesniffer.reporting.php

C:\wamp\bin\php\php5.3.0>phpcs –standard=Zend –report=xml –report-file=c:\wam
p\www\tests.xml c:\wamp\www\codesniffer_test\test.php

 

 

Resource:
http://techblog.wimgodden.be/tag/codesniffer/
http://docs.joomla.org/Joomla_CodeSniffer
http://pear.php.net/manual/en/package.php.php-codesniffer.usage.php
http://pear.php.net/package/PHP_CodeSniffer/redirected

Advertisements
  1. July 16, 2012 at 2:28 am

    great post

  2. December 5, 2012 at 1:22 pm

    PHP_CodeSniffer is a PHP5 program that tokenises and “sniffs” PHP, JavaScript and CSS information to identify offenses of a described programming standard

  3. JohnJohnson
    March 6, 2013 at 6:46 pm

    Use –standard instead of -standard

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: