Download the PHP package php-collective/code-sniffer without Composer
On this page you can find all versions of the php package php-collective/code-sniffer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download php-collective/code-sniffer
More information about php-collective/code-sniffer
Files in php-collective/code-sniffer
Package code-sniffer
Short Description PhpCollective Code Sniffer Standards
License MIT
Homepage https://github.com/php-collective/code-sniffer
Informations about the package code-sniffer
PhpCollective Code Sniffer
This sniffer package follows PSR-2 completely and ships with a lot of additional fixers on top (incl. PSR-12). Please see the PhpCollective Coding conventions for details.
List of included sniffs.
Documentation
See docs.
Upstream docs: squizlabs/PHP_CodeSniffer/wiki
Usage
How to use in projects
Make sure you include the sniffer as require-dev
dependency:
Then set up a phpcs.xml
file in your project ROOT, e.g.:
How to use in any project
You can manually invoke the phpcs/phpcbf commands:
The command phpcs
just sniffs, phpcbf
fixes.
It is recommended to set up composer scripts to have shortcuts:
Then you can run composer cs-c
and composer cs-f
and don't have to worry about the acronyms.
Standards
You can always switch the standard to the stricter one named PhpCollectiveStrict
.
It is an extension of the PhpCollective
standard with its own (strict) sniffs added on top.
How to include in your IDE
E.g. for PHPStorm:
- Open Settings -> Tools -> External Tools
- Add a new tool named "cs-sniffer" and set Program to
$ProjectFileDir$/vendor/bin/phpcs
, Parameters to--standard=$ProjectFileDir$/vendor/php-collective/code-sniffer/PhpCollective/ruleset.xml -p $FilePath$
and Working directory to$ProjectFileDir$
. - Add a new tool named "cs-fixer" and set Program to
$ProjectFileDir$/vendor/bin/phpcbf
, Parameters to--standard=$ProjectFileDir$/vendor/php-collective/code-sniffer/PhpCollective/ruleset.xml -v $FilePath$
and Working directory to$ProjectFileDir$
. - Remove the "Open console" if you don't want to see any output here for the fixer.
- Now set up your hotkeys under Settings -> Keymap (search for cs-sniffer and cs-fixer). E.g.
Control + Comma
for sniffing, andControl + Dot
for fixing.
You can also set up file watchers, but here you should better only whitelist certain sniffs that only add things and don't remove anything.
How to configure the default rule set
In order to simplify command line interface, phpcs
allows to specify default rule set in and standards path the following way.
Assuming the following directory structure:
The base directory and rule set can be used in configuration now.
You might need to specify full directory path. Now the tools can be used without --standard
switch.
Make sure that you include the PhpCollective core standard ruleset in your custom one, e.g.:
If you want to use the PhpCollectiveStrict
standard in your project, you should replace the string:
with this one:
All versions of code-sniffer with dependencies
slevomat/coding-standard Version ^8.16.0
squizlabs/php_codesniffer Version ^3.11.3