slevomat/coding-standard
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
dealerdirect/phpcodesniffer-composer-installer | v1.0.0 | 11.37 kB | MIT | prod | |
phpstan/phpdoc-parser | 1.29.0 | - | MIT | prod | |
squizlabs/php_codesniffer | 3.9.2 | - | BSD-3-Clause | prod |
Slevomat Coding Standard is a set of tools, also known as "sniffs," designed to enhance PHP_CodeSniffer. The Slevomat package checks PHP code for compliance with certain coding standards and best practices, which helps ensure code cleanliness, consistency, and safety. It offers functionality for not only enhancing code readability through format checks, but also improving its behavior and detecting dead code.
To use Slevomat Coding Standard, first, you have to add it to your project using Composer:
{
"require-dev": {
"slevomat/coding-standard": "~8.0"
}
}
A typical way to use selected sniffs from the standard on your codebase is by writing your own ruleset.xml file, where you can reference only the sniffs you need:
<?xml version="1.0"?>
<ruleset name="AcmeProject">
<config name="installed_paths" value="../../slevomat/coding-standard"/><!-- relative path from PHPCS source location -->
<rule ref="SlevomatCodingStandard.Arrays.TrailingArrayComma"/>
<!-- other sniffs to include -->
</ruleset>
Then, run the phpcs
executable:
vendor/bin/phpcs --standard=ruleset.xml --extensions=php --tab-width=4 -sp src tests
Some sniffs offer automatic fixing of errors. To use that feature, run phpcbf
instead of phpcs
:
vendor/bin/phpcbf --standard=ruleset.xml --extensions=php --tab-width=4 -sp src tests
The comprehensive documentation and guidelines for the slevomat/coding-standard package are conveniently included within the package itself. Specific guidance for each sniff can be found in the respective markdown files located within the doc
directory mentioned in the README file. For example, array-related sniffs can be found in doc/arrays.md
, class-related sniffs in doc/classes.md
, and so on. A good understanding of these documents will help you effectively utilize this powerful coding standard tool.