webservco / coding-standards
A collection of coding standards and configuration files. Shared, opinionated configuration for PHP_CodeSniffer, PHPStan, Psalm, Phan, PHPMD and PHPUnit, based on PSR-12 and Slevomat Coding Standard.
Package info
github.com/webservco/coding-standards
Type:phpcodesniffer-standard
pkg:composer/webservco/coding-standards
Requires
- php: ^8.4
Requires (Dev)
- pds/skeleton: ^1
- phan/phan: ^6
- php-parallel-lint/php-console-highlighter: ^1
- php-parallel-lint/php-parallel-lint: ^1
- phpmd/phpmd: ^3
- phpstan/phpstan: ^2
- phpstan/phpstan-deprecation-rules: ^2
- phpstan/phpstan-doctrine: ^2
- phpstan/phpstan-phpunit: ^2
- phpstan/phpstan-strict-rules: ^2
- phpstan/phpstan-symfony: ^2
- phpunit/phpunit: ^13
- psalm/plugin-symfony: ^5
- slevomat/coding-standard: ^8
- squizlabs/php_codesniffer: ^4
- vimeo/psalm: ^6
- weirdan/doctrine-psalm-plugin: ^2
Suggests
None
Provides
None
Conflicts
- phpmd/phpmd: <3
Replaces
None
This package is auto-updated.
Last update: 2026-10-31 17:42:16 UTC
README
A collection of coding standards and configuration files.
Shared, opinionated configuration for PHP_CodeSniffer, PHPStan, Psalm, Phan, PHPMD and PHPUnit, based on PSR-12 and Slevomat Coding Standard.
- Requires: PHP 8.4+
- Related:
webservco/component-common(the components' phpcs ruleset, built on this one)
Installation
composer require --dev webservco/coding-standards
The package only holds configuration files, so require each tool you use yourself. require-dev in composer.json lists the supported versions.
Usage
Run the tools from the project root, with paths pointing into vendor/webservco/coding-standards/. Every config expects the PDS skeleton directories (bin config public resources src tests).
| Tool | Config | Command |
|---|---|---|
| Phan 6 | phan/config.php |
vendor/bin/phan --config-file vendor/webservco/coding-standards/phan/config.php |
| PHPMD 3 | phpmd/phpmd-rule-set.xml |
vendor/bin/phpmd analyze --no-progress --format json --ruleset vendor/webservco/coding-standards/phpmd/phpmd-rule-set.xml bin config public resources src tests |
| PHPStan 2 | phpstan/phpstan.neon |
vendor/bin/phpstan analyse bin config public resources src tests --ansi -c vendor/webservco/coding-standards/phpstan/phpstan.neon |
| PHPUnit 12, 13 | phpunit/phpunit-13.xml |
XDEBUG_MODE=coverage vendor/bin/phpunit --colors=always --configuration vendor/webservco/coding-standards/phpunit/phpunit-13.xml |
| Psalm 6 | psalm/psalm.xml |
vendor/bin/psalm --config=vendor/webservco/coding-standards/psalm/psalm.xml --no-diff |
PHP_CodeSniffer
Create .phpcs/php-coding-standard.xml in the project:
<?xml version="1.0"?> <ruleset name="Project-CodingStandard"> <rule ref="vendor/webservco/coding-standards/phpcs/ruleset-psr-slevomat.xml"> </rule> <rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName"> <properties> <property name="rootNamespaces" type="array"> <element key="src/Project" value="Project" /> <element key="tests/Unit" value="Tests\Unit" /> </property> </properties> </rule> </ruleset>
vendor/bin/phpcs --standard=.phpcs/php-coding-standard.xml --extensions=php -sp bin config public resources src tests
The rulesets are phpcs/ruleset-psr.xml (PSR-12), phpcs/ruleset-psr-slevomat.xml (PSR-12 and Slevomat) and phpcs/ruleset-namespaces.xml (Slevomat namespace and use rules only).
Symfony
PHPStan and Psalm have -symfony and -symfony-doctrine variants of their configs. Require phpstan/phpstan-symfony and psalm/plugin-symfony, and for Doctrine also phpstan/phpstan-doctrine and weirdan/doctrine-psalm-plugin. The Doctrine PHPStan config also needs .phpstan/get_doctrine_manager.php, as described in the phpstan-doctrine documentation.
Notes
PHPStan runs at level max, with extra checks for uninitialized properties, callable signatures, possibly nonexistent array offsets, too wide return types and benevolent union types.
The PHPMD rule set uses rules that only exist in PHPMD 3, and composer.json conflicts with older versions. Separate paths with spaces. To suppress a warning, use the #[\PHPMD\Attribute\SuppressWarnings(...)] attribute. The @SuppressWarnings annotation is deprecated, and the UnusedSuppression rule doesn't check it.
The PHPUnit configs set the --display-* options and write coverage to var/tmp/phpunit/. With ddev, run ddev xdebug on first.
Upgrading from v1
- PHP_CodeSniffer: replace
phpcs/ruleset-psr-phpXY.xmlwithphpcs/ruleset-psr.xml, andphpcs/ruleset-psr-phpXY-slevomat.xmlwithphpcs/ruleset-psr-slevomat.xml. PHPCompatibility is gone: removephpcompatibility/php-compatibilityand anyPHPCompatibilityortestVersionlines, then require"squizlabs/php_codesniffer": "^4". Newer Slevomat versions add sniffs such asSlevomatCodingStandard.Classes.ReadonlyClass, so expect new errors. - PHPUnit: only the 12 and 13 configs remain. Remove
--display-*options from your scripts. - PHPStan: the stricter checks above are new, so expect new errors.
- Phan: requires Phan 6.
UnusedSuppressionPluginis enabled.