webservco / coding-standards
Custom, opinionated coding standards based on PSR12 and SlevomatCodingStandard.
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-04 18:31:30 UTC
README
A collection of coding standards and configuration files.
Custom, opinionated coding standards based on PSR12 and SlevomatCodingStandard.
Setup
composer require --dev webservco/coding-standards
Optionally, install any of the dependencies from require-dev that you wish to use in your project.
Upgrading from v1
- PHP_CodeSniffer:
- the versioned rulesets were removed: replace
phpcs/ruleset-psr-phpXY.xmlwithphpcs/ruleset-psr.xmlandphpcs/ruleset-psr-phpXY-slevomat.xmlwithphpcs/ruleset-psr-slevomat.xml; - PHPCompatibility is no longer included: remove
phpcompatibility/php-compatibilityfrom your project (and anyPHPCompatibility/testVersionlines from your own ruleset), then require"squizlabs/php_codesniffer": "^4"to get current Slevomat versions; - newer Slevomat versions add sniffs (e.g.
SlevomatCodingStandard.Classes.ReadonlyClass), so expect new errors.
- the versioned rulesets were removed: replace
- PHPUnit: only
phpunit/phpunit-12.xmlandphpunit/phpunit-13.xmlare provided; the--display-*options are now set in the configuration files and can be removed from your scripts. - PHPStan: stricter checks are enabled (uninitialized properties, callable signatures, possibly nonexistent array offsets, too wide return types, benevolent union types), so expect new errors.
- Phan: requires Phan 6;
UnusedSuppressionPluginis enabled.
Components
Phan
Usage:
vendor/bin/phan --config-file vendor/webservco/coding-standards/phan/config.php
PHP_CodeSniffer
Example configuration file .phpcs/php-coding-standard.xml, to be placed in own project:
<?xml version="1.0"?> <ruleset name="Project-CodingStandard"> <description>Custom, opinionated coding standards based on PSR12 and SlevomatCodingStandard.</description> <rule ref="vendor/webservco/coding-standards/phpcs/ruleset-psr-slevomat.xml"> <properties> <property name="rootNamespaces" type="array"> <element key="src/Project" value="Project" /> <element key="tests/unit" value="Tests" /> </property> </properties> </rule> </ruleset>
Usage:
vendor/bin/phpcs --standard=.phpcs/php-coding-standard.xml --extensions=php -sp bin config public resources src tests
Rulesets:
phpcs/ruleset-psr.xml: PSR-12;phpcs/ruleset-psr-slevomat.xml: PSR-12, Slevomat;phpcs/ruleset-namespaces.xml: Slevomat namespace usage.
PHPMD
Requires PHPMD 3 ("phpmd/phpmd": "^3"). The rule set uses PHPMD 3 only rules, so it does not work with PHPMD 2.
Usage:
vendor/bin/phpmd analyze --no-progress --format json --ruleset vendor/webservco/coding-standards/phpmd/phpmd-rule-set.xml bin config public resources src tests
Paths are separated by spaces; comma-separated paths are only accepted by the deprecated PHPMD 2 style command (phpmd <paths> <format> <ruleset>).
Suppressing warnings: prefer the #[\PHPMD\Attribute\SuppressWarnings(...)] attribute; @SuppressWarnings annotations are deprecated in PHPMD 3 and are not checked by the UnusedSuppression rule.
PHPStan
Symfony support
- install symfony related packages:
- (if using Doctrine) "phpstan/phpstan-doctrine": "^2",
- "phpstan/phpstan-symfony": "^2",
- (if using Doctrine) create
.phpstan/get_doctrine_manager.php, as in phpstan-doctrine documentation - use specific
phpstan-symfony.neonorphpstan-symfony-doctrine.neonconfiguration files
Usage:
vendor/bin/phpstan analyse bin config public resources src tests --ansi -c vendor/webservco/coding-standards/phpstan/phpstan.neon
PHPUnit
Composer scripts example:
{
"scripts": {
"test" : "XDEBUG_MODE=coverage vendor/bin/phpunit --colors=always --configuration vendor/webservco/coding-standards/phpunit/phpunit-13.xml",
"test:dox" : "@test --testdox"
}
}
Usage:
ddev xdebug on clear && ddev exec XDEBUG_MODE=coverage composer test:dox
Psalm
Usage:
vendor/bin/psalm --config=vendor/webservco/coding-standards/psalm/psalm.xml --no-diff