pixelfederation / coding-standards
Standardized PHPCS sniffs for backend developers.
Installs: 63 915
Dependents: 3
Suggesters: 0
Security: 0
Stars: 1
Watchers: 8
Forks: 0
Open Issues: 3
Language:Dockerfile
Requires
- php: ^8.1
- phpcompatibility/php-compatibility: ^9.3.5
- slevomat/coding-standard: ^8.12.1
- squizlabs/php_codesniffer: ^3.7.2
This package is auto-updated.
Last update: 2024-12-12 09:38:23 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="8.1"/><!-- 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> </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