spryker / code-sniffer
Spryker Code Sniffer Standards
Installs: 3 357 866
Dependents: 2 267
Suggesters: 0
Security: 0
Stars: 36
Watchers: 64
Forks: 11
Open Issues: 7
Type:phpcodesniffer-standard
Requires
- php: >=8.1
- slevomat/coding-standard: ^7.2.0 || ^8.0.1
- squizlabs/php_codesniffer: ^3.6.2
Requires (Dev)
- phpstan/phpstan: ^1.0.0
- phpunit/phpunit: ^9.5
- dev-master
- 0.17.25
- 0.17.24
- 0.17.23
- 0.17.22
- 0.17.21
- 0.17.20
- 0.17.19
- 0.17.18
- 0.17.17
- 0.17.16
- 0.17.15
- 0.17.14
- 0.17.13
- 0.17.12
- 0.17.11
- 0.17.10
- 0.17.9
- 0.17.8
- 0.17.7
- 0.17.6
- 0.17.5
- 0.17.4
- 0.17.3
- 0.17.2
- 0.17.1
- 0.17.0
- 0.16.6
- 0.16.5
- 0.16.4
- 0.16.3
- 0.16.2
- 0.16.1
- 0.16.0
- 0.15.9
- 0.15.8
- 0.15.7
- 0.15.6
- 0.15.5
- 0.15.4
- 0.15.3
- 0.15.2
- 0.15.1
- 0.15.0
- 0.14.12
- 0.14.11
- 0.14.10
- 0.14.9
- 0.14.8
- 0.14.7
- 0.14.6
- 0.14.5
- 0.14.4
- 0.14.3
- 0.14.2
- 0.14.1
- 0.14.0
- 0.13.1
- 0.13.0
- 0.12.5
- 0.12.4
- 0.12.3
- 0.12.2
- 0.12.1
- 0.12.0
- 0.11.4
- 0.11.3
- 0.11.2
- 0.11.1
- 0.11.0
- 0.10.4
- 0.10.3
- 0.10.2
- 0.10.1
- 0.10.0
- 0.9.5
- 0.9.4
- 0.9.3
- 0.9.2
- 0.9.1
- 0.9.0
- 0.8.2
- 0.8.1
- 0.8.0
- 0.7.2
- 0.7.1
- 0.7.0
- 0.6.11
- 0.6.10
- 0.6.9
- 0.6.8
- 0.6.7
- 0.6.6
- 0.6.5
- 0.6.4
- 0.6.3
- 0.6.2
- 0.6.1
- 0.6.0
- 0.5.2
- 0.5.1
- 0.5
- 0.4.3
- 0.4.2
- 0.4.1
- 0.4.0
- 0.3.1
- 0.3
- 0.2
- 0.1
- dev-strict-call
- dev-uselessparentheses
This package is auto-updated.
Last update: 2024-10-07 04:46:22 UTC
README
This sniffer package follows PSR-2 completely and ships with a lot of additional fixers on top (incl. PSR-12). Please see the Spryker Coding conventions for details.
Documentation
See docs.
Upstream docs: squizlabs/PHP_CodeSniffer/wiki
Usage
How to use in Spryker projects
Make sure you include the sniffer as require-dev
dependency:
composer require --dev spryker/code-sniffer
The Development module provides a convenience command:
console code:sniff:style
(or console c:s:s
as shortcut)
To automatically fix fixable errors, use
console code:sniff:style -f
-v
is useful for more info output.
To run only a specific sniff, use the -s
option. See -h
for help.
You can also sniff a specific project level module or path:
console code:sniff:style [-m ModuleName] [optional-sub-path] -v
How to use in any project
You can also manually invoke the phpcs/phpcbf commands:
vendor/bin/phpcs --standard=vendor/spryker/code-sniffer/Spryker/ruleset.xml ./
vendor/bin/phpcbf --standard=vendor/spryker/code-sniffer/Spryker/ruleset.xml ./
The command phpcs
just sniffs, phpcbf
fixes.
You probably want to ignore some folders, e.g. --ignore=vendor/
or some of your test fixture folders.
Standards
You can always switch the standard to the stricter one named SprykerStrict
.
It is an extension of the Spryker
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/spryker/code-sniffer/Spryker/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/spryker/code-sniffer/Spryker/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:
vendor/spryker/code-sniffer/ # Base directory
|_ Spryker/ # Rule set name
|_ ruleset.xml # Rule set
The base directory and rule set can be used in configuration now.
vendor/bin/phpcs --config-set installed_paths vendor/spryker/code-sniffer/
vendor/bin/phpcs --config-set default_standard Spryker
You might need to specify full directory path. Now the tools can be used without --standard
switch.
Using own project standard
You can exchange or extend the Spryker coding standard by providing your own ruleset.xml. This can be configured in the Development module config:
// DevelopmentConfig.php /** * Either a relative or full path to the ruleset.xml or a name of an installed * standard (see `phpcs -i` for a list of available ones). * * @return string */ public function getCodingStandard() { return '/path/to/your/ruleset.xml'; }
If you use it for custom projects, just use --standard
to point to your ruleset file.
Make sure that you include the Spryker core standard ruleset in your custom one, e.g.:
<?xml version="1.0"?> <ruleset name="SprykerProject"> <description> Spryker Coding Standard for Project. Extends main Spryker Coding Standard. All sniffs in ./Sniffs/ will be auto loaded </description> <rule ref="vendor/spryker/code-sniffer/Spryker/ruleset.xml"/> <exclude-pattern>*/src/Generated/*</exclude-pattern> <exclude-pattern>*/src/Orm/*</exclude-pattern> <exclude-pattern>*/tests/_support/_generated/*</exclude-pattern> <exclude-pattern>*/tests/_helpers/*</exclude-pattern> <exclude-pattern>*/tests/_output/*</exclude-pattern> <exclude-pattern>./data/DE/*</exclude-pattern> <!-- Define your own sniffs here --> </ruleset>
If you want to use the SprykerStrict
standard in your project, you should replace the string:
<rule ref="vendor/spryker/code-sniffer/Spryker/ruleset.xml"/>
with this one:
<rule ref="vendor/spryker/code-sniffer/SprykerStrict/ruleset.xml"/>