symplify/coding-standard
Opinionated PHP coding standard with 23 fixers for clean, consistent, readable code—no config required. Designed to run with Symplify Easy Coding Standard (ECS); install via Composer and auto-fix formatting like arrays, strict types spacing, line length, and method chaining.
Installation:
composer require symplify/coding-standard symplify/easy-coding-standard --dev
symplify/easy-coding-standard (ECS) is installed as the core runner.Configuration:
Add the Symplify set to your ecs.php:
use Symplify\EasyCodingStandard\Config\ECSConfig;
return ECSConfig::configure()
->withPreparedSets(symplify: true);
First Run:
vendor/bin/ecs check # Dry-run (no changes)
vendor/bin/ecs fix # Auto-fix violations
ecs fix during a new developer’s setup to standardize their codebase contributions.ecs check in CI to enforce consistency before merging.Team Enforcement:
pre-commit) to auto-fix issues:
composer require --dev laravel-pint/laravel-pint # Optional: Combine with Pint
.git/hooks/pre-commit:
#!/bin/sh
vendor/bin/ecs check --diff
Customization:
->withPaths(['src/', 'tests/'])
->withSkip(['src/legacy/*.php']);
LineLengthFixer):
->withRule(Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer::class)
->lineLength(120)
->skip(['*/migrations/*.php']);
CI/CD:
# .github/workflows/ecs.yml
jobs:
ecs:
runs-on: ubuntu-latest
steps:
- run: vendor/bin/ecs check
@phpstan-/@psalm- prefixed docblock rules (e.g., AddMissingParamNameFixer).vendor/, bootstrap/, and config/ from checks:
->withPaths(['app/', 'routes/', 'database/']);
--parallel:
vendor/bin/ecs fix --parallel
False Positives:
RemovePropertyVariableNameDescriptionFixer may misfire on complex PHPDoc blocks. Test edge cases like:
/** @var string $name|string[] */
--skip:
vendor/bin/ecs fix --skip=RemovePropertyVariableNameDescriptionFixer
Performance:
--parallel or split paths:
vendor/bin/ecs check app/ tests/
Overzealous Fixes:
->withRule(LineLengthFixer::class)->skip(['*/migrations/*.php']);
--diff to preview changes:
vendor/bin/ecs check --diff
vendor/bin/ecs fix -vvv
Custom Rules:
Extend Symplify\EasyCodingStandard\ValueObject\Option to add new fixers:
// CustomFixer.php
use Symplify\EasyCodingStandard\Fixer\FixerInterface;
class CustomFixer implements FixerInterface { ... }
// ecs.php
->withRule(CustomFixer::class);
Rule Sets: Combine with other sets (e.g., PSR12):
->withPreparedSets(
symplify: true,
psr12: true
);
Conditional Rules:
Use ECSConfig::configure() to conditionally enable rules:
->withRule(StandaloneLineConstructorParamFixer::class)
->if($this->isPHP80());
CONTRIBUTING.md snippet:
## Code Standards
Run `composer ecs` to auto-fix issues before committing.
How can I help you explore Laravel packages today?