pixelfederation / coding-standards
Standardized PHPCS sniffs for backend developers.
Installs: 62 786
Dependents: 3
Suggesters: 0
Security: 0
Stars: 1
Watchers: 9
Forks: 0
Open Issues: 3
Requires
- php: ~7.4.0|^8.1
- phpcompatibility/php-compatibility: ^9.3.5
- slevomat/coding-standard: ^8.12.1
- squizlabs/php_codesniffer: ^3.7.2
Requires (Dev)
- madewithlove/license-checker: ^0.10.0
This package is auto-updated.
Last update: 2024-11-04 09:04:05 UTC
README
This package provides PHPCS rule set for coding standards in Pixel Federation. It should be included into each project maintained by Pixel Federation that uses PHP Code Sniffer PHPCS.
Example usage
1) Install composer dependencies
composer require pixelfederation/coding-standards:^2.0 --dev
2) Ruleset creation
Create a file named phpcs.ruleset.xml
to the root folder of your project with the following content:
<?xml version="1.0"?> <ruleset name="PixelFederation"> <description>PixelFederation rule set.</description> <config name="testVersion" value="7.2-7.4"/><!-- insert your php version --> <exclude-pattern>tests/</exclude-pattern> <rule ref="vendor/pixelfederation/coding-standards/phpcs.ruleset.xml"> <!-- old projects may want to exclude these rules: --> <!-- <exclude name="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming"/> <exclude name="SlevomatCodingStandard.Classes.SuperfluousTraitNaming"/> <exclude name="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming"/> <exclude name="SlevomatCodingStandard.Classes.SuperfluousExceptionNaming"/> --> <!-- <exclude name="SlevomatCodingStandard.Files.FunctionLength"/> --> </rule> <rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName"> <properties> <property name="rootNamespaces" type="array"> <element key="src" value="Your\Root\Namespace"/><!-- add your namespaces --> </property> </properties> </rule> <!-- include for PHP 7.2- --> <!-- <rule ref="SlevomatCodingStandard.Functions.DisallowTrailingCommaInCall"/>--> <!-- include for PHP 7.3+ --> <!-- <rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInCall"/>--> <!-- include for PHP 7.4+ --> <!-- <rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint"/>--> <!-- <rule ref="SlevomatCodingStandard.Functions.ArrowFunctionDeclaration"/>--> </ruleset>
Running checks
In your project directory run this command:
vendor/bin/phpcs --standard=phpcs.ruleset.xml --extensions=php --tab-width=4 -sp src
Automatically fixing errors
In your project directory run this command:
vendor/bin/phpcbf --standard=phpcs.ruleset.xml --extensions=php --tab-width=4 -sp src
Additional links
Sniffs documentation for slevomat coding standards are here: https://github.com/slevomat/coding-standard