Skip to main content

Tedshd's Dev note

PHP - install phpcs(PHP CodeSniffer)

Table of Contents

# PHP - install phpcs(PHP CodeSniffer)

Use pear install phpcs

## in Linux(Ubuntu 14.04)

sudo pear install --alldeps php_codesniffer

## in Mac(Mac OS X 10.10.1 Yosemite)

### install pear

sudo curl -O  http://pear.php.net/go-pear.phar

then

sudo php -d detect_unicode=0 go-pear.phar

Update

pear upgrade pear
pear upgrade

### install codesniffer

sudo pear install --alldeps php_codesniffer

check

phpcs -i

return

The installed coding standards are MySource, PEAR, PHPCS, PSR1, PSR2, Squiz and Zend

if return

Warning: include_once(PHP/CodeSniffer/CLI.php): failed to open stream: No such file or directory in /usr/bin/phpcs on line 22

Warning: include_once(): Failed opening 'PHP/CodeSniffer/CLI.php' for inclusion (include_path='.:') in /usr/bin/phpcs on line 22

Fatal error: Class 'PHP_CodeSniffer_CLI' not found in /usr/bin/phpcs on line 25

Must include pear path

Modify php.ini

sudo vim /etc/php.ini
include_path = ".:/usr/share/pear"

## Usage

phpcs <php file>

Refer - PEAR - PHP Extension and Application Repository Refer - PHP_CodeSniffer Refer - Code Sniffer Refer - Installing PEAR on OSX 10.9 Mavericks and OSX10.8/10.7