eXolnet configuration for PHP CodeSniffer.
A collection of shareable configurations for various coding-style tools to make the configurations consistent across our projects.
composer require --dev exolnet/phpcs-config
- Run the following command to run the standards checks:
vendor/bin/phpcs --standard=vendor/exolnet/phpcs-config .
You can add this to your Travis YAML file as a test:
script: - phpunit - vendor/bin/phpcs --standard=vendor/exolnet/phpcs-config .
This standard includes special support for a
.phpcsignore file (in the future, this should be built into phpcs itself).
Simply place a
.phpcsignore file in your root directory (wherever you're going to run
The format of this file is similar to
.gitignore and similar files: one pattern per line, comment lines should start with a
#, and whitespace-only lines are ignored:
# Exclude our tests directory. tests/ # Exclude any file ending with ".inc" *\.inc
Note that the patterns should match the PHP_CodeSniffer style:
* is translated to
.* for convenience, but all other characters work like a regular expression.
Patterns are relative to the directory that the
.phpcsignore file lives in. On load, they are translated to absolute patterns: e.g.
/your/dir/.phpcsignore will become
/your/dir/.*/tests/.* as a regular expression. This differs from the regular PHP_CodeSniffer practice.
If you want to add further rules (such as laravel-specific rules), you can create your own custom standard file (e.g.
<?xml version="1.0"?> <ruleset> <file>app</file> <file>config</file> <file>database</file> <file>routes</file> <file>tests</file> <!-- Use eXolnet Coding Standards --> <rule ref="vendor/exolnet/phpcs-config" /> <!-- Add Laravel-specific rules --> <rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace"> <exclude-pattern>database/*</exclude-pattern> </rule> </ruleset>
You can then reference this file when running phpcs:
vendor/bin/phpcs --standard=ruleset.xml .
You can also customise the rule to exclude elements if they aren't applicable to the project:
<rule ref="vendor/exolnet/phpcs-config"> <!-- Disable short array syntax --> <exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace" /> </rule>
To find out what these codes are, specify
-s when running
phpcs, and the code will be output as well. You can specify a full code, or a partial one to disable groups of errors.
If you discover any security related issues, please email email@example.com instead of using the issue tracker.