wdes / coding-standard
The Wdes coding standard
Package info
github.com/wdes/coding-standard
Type:phpcodesniffer-standard
pkg:composer/wdes/coding-standard
v3.3.2
2023-12-16 21:44 UTC
Requires
- php: ^7.2 || ^8.0
- slevomat/coding-standard: ^8.14.1
- squizlabs/php_codesniffer: ^3.8.0
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
The Wdes coding-standard
Rules to disable for PHP < 5.4 compatibility
Generic.Arrays.DisallowLongArraySyntax
Rules to disable for PHP < 7 compatibility
SlevomatCodingStandard.Classes.ClassConstantVisibility.MissingConstantVisibility
How to add it
- Run
composer require --dev wdes/coding-standard - Create file:
phpcs.xmlwith the contents below
xml version="1.0" encoding="UTF-8"?> <ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd"> <arg value="ps"/> <arg name="cache" value=".php_cs.cache"/> <arg name="colors"/> <arg name="basepath" value="."/> <file>.file> <exclude-pattern>*/tmp/*exclude-pattern> <exclude-pattern>*/vendor/*exclude-pattern> <exclude-pattern>*/build/*exclude-pattern> <exclude-pattern>*/node_modules/*exclude-pattern> <rule ref="Wdes">rule> ruleset>
-
Remove phpcs from your dev deps if you have it, we require it for you. Use
composer remove squizlabs/php_codesniffer --dev -
Run
./vendor/bin/phpcsto see the coding standard errors -
Run
./vendor/bin/phpcbfto try to fix them
Recommended composer.json config
"scripts": { "phpcbf": "@php phpcbf", "phpcs": "@php phpcs", ... }, "config": { ... "allow-plugins": { "dealerdirect/phpcodesniffer-composer-installer": true } },
How to exclude rules
Examples of ways to exclude rules
xml version="1.0" encoding="UTF-8"?> <ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd"> <arg value="ps"/> <arg name="cache" value=".php_cs.cache"/> <arg name="colors"/> <file>srcfile> <file>scriptsfile> <file>examplesfile> <file>testsfile> <exclude-pattern>*/src/Resources/themes/*exclude-pattern> <exclude-pattern>*/tests/phar/data/**/*exclude-pattern> <rule ref="Wdes"> <exclude name="Generic.Formatting.MultipleStatementAlignment.NotSameWarning"/> rule> <rule ref="Generic.Files.LineLength.TooLong"> <severity>0severity> rule> <exclude name="PSR1.Files.SideEffects.FoundWithSymbols"/> <rule ref="Generic.PHP.NoSilencedErrors.Discouraged"> <exclude-pattern>*exclude-pattern> rule> <rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace"> <exclude-pattern>db/migrations/*exclude-pattern> rule> <rule ref="Squiz.PHP.DiscouragedFunctions.Found"> <exclude-pattern>src/libs/Logger.phpexclude-pattern> rule> ruleset>