fundrik / coding-standard
Custom PHP_CodeSniffer rules for Fundrik
Package info
github.com/fundrik/coding-standard
Type:phpcodesniffer-standard
pkg:composer/fundrik/coding-standard
Requires
- php: ^8.3
- phpcompatibility/phpcompatibility-wp: ^3.0@dev
- slevomat/coding-standard: ^8.22
- wp-coding-standards/wpcs: ^3.4
Requires (Dev)
- dealerdirect/phpcodesniffer-composer-installer: ^1.2
- phpunit/phpunit: ^12.5
- rector/rector: ^2.6
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
A PHP_CodeSniffer standard for Fundrik PHP projects.
Fundrik Coding Standard combines WordPress Coding Standards, PHPCompatibilityWP, and selected Slevomat Coding Standard rules with Fundrik-specific sniffs. It is intended for Fundrik projects and other modern PHP 8.3+ WordPress codebases that want the same conventions.
Requirements
- PHP 8.3 or later.
- Composer 2.
Installation
Install the standard as a development dependency:
composer require --dev fundrik/coding-standard
The package uses dealerdirect/phpcodesniffer-composer-installer, so Composer registers FundrikStandard with PHP_CodeSniffer automatically. Composer may ask you to allow that plugin during installation.
Usage
Create a phpcs.xml in your project:
<?xml version="1.0"?> <ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Project Name" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd"> <exclude-pattern>vendor/</exclude-pattern> <arg value="sp"/> <arg name="basepath" value="."/> <arg name="colors"/> <arg name="extensions" value="php"/> <!-- Adjust to the number of CPU cores available. --> <arg name="parallel" value="8"/> <config name="testVersion" value="8.3-"/> <rule ref="FundrikStandard"/> </ruleset>
Run PHP_CodeSniffer through the project's installed binary:
vendor/bin/phpcs . vendor/bin/phpcbf .
phpcs reports violations. phpcbf automatically fixes violations supported by the underlying sniff; rules that require design decisions remain manual fixes.
Included rules
The aggregate FundrikStandard ruleset enables:
- selected Slevomat rules for modern PHP structure, type declarations, control flow, namespaces, and formatting;
- PHPCompatibilityWP checks for the configured target PHP version;
- WordPress Coding Standards, with targeted exclusions documented in the ruleset;
- Fundrik-specific sniffs:
FundrikStandard.Classes.AbstractClassMustBeReadonlyrequires abstract classes to be declaredreadonly;FundrikStandard.Classes.FinalClassMustBeReadonlyrequires final classes to be declaredreadonly;FundrikStandard.Classes.RequireAbstractOrFinalrequires classes to be declaredabstractorfinal;FundrikStandard.Commenting.SinceTagRequiredrequires@sincein docblocks for classes, interfaces, traits, enums, functions, and methods;FundrikStandard.Functions.FunctionBodyEmptyLineBeforerequires an empty line between a function body's opening brace and its first statement.
The complete, authoritative rule list is in FundrikStandard/ruleset.xml.
Configuring class exclusions
AbstractClassMustBeReadonly, FinalClassMustBeReadonly, and RequireAbstractOrFinal support excludedClasses and excludedParentClasses. Use these properties for framework types or other classes that cannot satisfy the default rule:
<rule ref="FundrikStandard.Classes.FinalClassMustBeReadonly"> <properties> <property name="excludedClasses" type="array"> <element value="Acme\Legacy\MutableService"/> </property> <property name="excludedParentClasses" type="array"> <element value="RuntimeException"/> </property> </properties> </rule>
The excludedParentClasses setting also applies to implemented interfaces where supported by the sniff.
Development
The Composer scripts are the source of truth for project checks:
Run checks for the regular local or pull request verification. It covers the checks required by the checks workflow:
composer run checks
Run release-checks before creating a release. It covers the checks required by the release-checks workflow, including random test ordering and coverage:
composer run release-checks
For a focused subset, run composer-checks after changing composer.json, composer.lock, or Composer autoload configuration. It validates the Composer configuration, dependencies, and autoloading, and is already included in both aggregate workflows:
composer run composer-checks
Run individual tools when troubleshooting a specific failure:
composer run lint
composer run rector -- --dry-run
composer run test
Changelog
See CHANGELOG.md for release history.
License
Fundrik Coding Standard is released under the MIT License.