29/07
2014
Wallogit.com
2017 © Pedro Peláez
CTLT PHP CodeSniffer Coding Standard
A code standard based on Symfony 2 coding standards., (*1)
Add the dependency to composer.json:, (*2)
{
"require-dev": {
"ubc/ctlt-coding-standard": "~1.0",
}
}
Install dependencies, (*3)
composer update, (*4)
Use it, (*5)
phpcs --standard=vendor/ubc/ctlt-coding-standard/ruleset.xml --runtime-set installed_paths vendor/m6web/symfony2-coding-standard src/*, (*6)
Or add the following Phing task:, (*7)
<target name="phpcs"
description="Find coding standard violations using PHP_CodeSniffer and print human readable output. Intended for usage on the command line before committing.">
<phpcodesniffer standard="${vendordir}/ubc/ctlt-coding-standard/ruleset.xml">
<config name="installed_paths" value="${vendordir}/m6web/symfony2-coding-standard"/>
<fileset dir="${sourcedir}">
<include name="**/*.php" />
</fileset>
</phpcodesniffer>
</target>
Install phpcs:, (*8)
pear install PHP_CodeSniffer
Find your PEAR directory:, (*9)
pear config-show | grep php_dir
Copy, symlink or check out this repo and Symfony2 coding standard to the
phpcs Standards directory:, (*10)
cd /path/to/pear/PHP/CodeSniffer/Standards git clone git://github.com/opensky/Symfony2-coding-standard.git Symfony2 git clone git://github.com/ubc/CTLT-PHP-coding-standard.git CTLT
Set CTLT as your default coding standard:, (*11)
phpcs --config-set default_standard CTLT
..., (*12)
Profit!, (*13)
cd /path/to/my/project phpcs phpcs path/to/my/file.php