This package provides the shared PHP_CodeSniffer rules and GrumPHP tasks used by Pixel Federation PHP projects.
- PHP 8.4 or 8.5
- PHP_CodeSniffer 4
- Slevomat Coding Standard 8
composer require --dev pixelfederation/coding-standardsThe package contains rulesets for PHP 8.4 and PHP 8.5. Each PHP version has a standard ruleset and a less restrictive ruleset for projects that do not use DDD:
| PHP | Standard ruleset | Non-DDD ruleset |
|---|---|---|
| 8.4 | phpcs.ruleset.84.xml |
phpcs.ruleset.84.non-ddd.xml |
| 8.5 | phpcs.ruleset.85.xml |
phpcs.ruleset.85.non-ddd.xml |
Create phpcs.ruleset.xml in the project root:
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="PixelFederation">
<description>Project coding standard.</description>
<exclude-pattern>tests/</exclude-pattern>
<rule ref="vendor/pixelfederation/coding-standards/phpcs.ruleset.84.xml">
<!-- Project-specific exclusions can be added here. -->
<exclude name="SlevomatCodingStandard.Functions.FunctionLength"/>
</rule>
</ruleset>Run the checks with:
vendor/bin/phpcs --standard=phpcs.ruleset.xml srcAutomatically fix supported violations with:
vendor/bin/phpcbf --standard=phpcs.ruleset.xml srcThe complete Slevomat sniff documentation is available in the Slevomat Coding Standard repository.
Custom tasks require the Composer installation of GrumPHP. They do not work with phpro/grumphp-shim when
parallel execution is enabled because PHAR task classes cannot be serialized.
Register the extension in the project's grumphp.yml:
grumphp:
extensions:
- PixelFederation\CodingStandards\GrumPHP\ExtensionLoadergrumphp:
tasks:
doctrine_schema_validate:
console_path: bin/console
em: default
skip_mapping: false
skip_property_types: false
skip_sync: false
triggered_by: [php, xml, yml]For multiple entity managers, configure multiple tasks using the shared task implementation:
grumphp:
tasks:
doctrine_schema_validate_application:
em: application
metadata:
task: doctrine_schema_validate
doctrine_schema_validate_reporting:
em: reporting
metadata:
task: doctrine_schema_validateOptions:
| Option | Default | Description |
|---|---|---|
console_path |
bin/console |
Path to the Symfony console. |
em |
null |
Entity manager name. Requires Doctrine ORM 3 or newer. |
skip_mapping |
false |
Skip mapping validation. |
skip_property_types |
null |
Skip the Doctrine property type check. Requires Doctrine ORM 3 or newer. |
skip_sync |
false |
Skip the database synchronization check. |
triggered_by |
[php, xml, yml] |
File extensions that trigger the task. |
This task checks whether changes to Composer files require dependencies to be installed again.
grumphp:
tasks:
composer_install_check:
script: ./vendor/pixelfederation/coding-standards/bin/composer_install_check.sh
ignore_patterns: []
triggered_by: [json, lock, php, xml, yaml, yml]
whitelist_patterns: []
metadata:
priority: 900Options:
| Option | Default | Description |
|---|---|---|
script |
./vendor/pixelfederation/coding-standards/bin/composer_install_check.sh |
Path to the check script. |
ignore_patterns |
[] |
Patterns excluded from the check. |
triggered_by |
[json, lock, php, xml, yaml, yml] |
File extensions that trigger the task. |
whitelist_patterns |
[] |
Patterns limiting which changed files are checked. |
This task extends the standard PHPStan task and splits files into smaller chunks to avoid operating-system command length limits.
grumphp:
tasks:
phpstan_extended:
autoload_file: ~
chunk_size: 1000
configuration: phpstan.neon
force_patterns: []
ignore_patterns: []
level: max
memory_limit: "-1"
triggered_by: [php]
use_grumphp_paths: truechunk_size determines the maximum number of files processed by one PHPStan execution.
This task extends the standard XMLLint task with DTD, XInclude, and XML Schema validation. It requires the dom
and libxml PHP extensions.
grumphp:
tasks:
xmllint_extended:
dtd_validation: false
ignore_patterns: []
load_from_net: false
scheme_validation: false
triggered_by: [xml]
x_include: falseWhen schema validation is enabled, the linter supports xsi:noNamespaceSchemaLocation and multi-namespace
xsi:schemaLocation documents. Imported namespaces are resolved by the root document schema.