I have a PHP library that I'm planning to submit to the PEAR database. In order to do this, the library needs to follow the PEAR Coding Standards.
Is there a tool that can check my code to make sure it follows the standards completely?
PHP Code Sniffer (PHPCS) is a package for syntax checking, available from PEAR. It can check code against defined rules covering anything from whitespace through doc comments to variable naming conventions and beyond.
In the Settings dialog, go to Editor > Inspections. From the inspections screen, expand the PHP | Quality tools node and enable “PHP CodeSniffer validation”. In the configuration pane that is now enabled, select “Custom” from the “Coding standard” dropdown, locate the ruleset configuration ( phpcs.
Overview. Code MUST follow a "coding style guide" PSR [PSR-1]. Code MUST use 4 spaces for indenting, not tabs. There MUST NOT be a hard limit on line length; the soft limit MUST be 120 characters; lines SHOULD be 80 characters or less.
http://pear.php.net/manual/en/package.php.php-codesniffer.php
By default, PHP_CodeSniffer will use the PEAR coding standard if no standard is supplied on the command line.
As B00MER mentioned, PHP_CodeSniffer defaults to using the PEAR coding standard, if you don't specify a different one. But you can change what it defaults to - handy if you have an in-house standard (which isn't really a standard then, but anyway) or prefer one of the other standards that ships with PHP_CodeSniffer and don't want to keep specifying them with the --standard argument.
To get a list of what Standards are available to choose from, do this:
$ phpcs -i
And to change the default to Zend:
$ sudo phpcs --config-set default_standard Zend
If you want to check what the default is:
$ phpcs --config-show
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With