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.
composer require pixelfederation/coding-standards:^2.0 --dev
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>
In your project directory run this command:
vendor/bin/phpcs --standard=phpcs.ruleset.xml --extensions=php --tab-width=4 -sp src
In your project directory run this command:
vendor/bin/phpcbf --standard=phpcs.ruleset.xml --extensions=php --tab-width=4 -sp src
Sniffs documentation for slevomat coding standards are here: https://github.com/slevomat/coding-standard