contao/easy-coding-standard
Adds Easy Coding Standard support for Contao projects, providing a ready-to-use ECS configuration and rules to enforce consistent PHP coding style and quality checks across your codebase, helping keep formatting and standards aligned in CI and local workflows.
Installation
composer require --dev contao/easy-coding-standard
Add the package to your project’s composer.json under require-dev.
First Run Execute the default Contao ruleset:
vendor/bin/ecs check src --config=vendor/contao/easy-coding-standard/ecs.php
Or integrate it into your CI pipeline (e.g., GitHub Actions, GitLab CI).
Where to Look First
vendor/contao/easy-coding-standard/ecs.php for predefined rules.ecs.php) and modifying it.First Use Case
Run ECS on your Contao project’s src/ directory to enforce PSR-12, Contao-specific coding standards, and best practices:
vendor/bin/ecs check src
Integrate into CI/CD Add ECS to your workflow (e.g., GitHub Actions):
- name: Run EasyCodingStandard
run: vendor/bin/ecs check src --config=ecs.php
Custom Rulesets Extend the default ruleset by merging with your own:
// ecs.php
use PhpCsFixer\Config;
use Symplify\EasyCodingStandard\ValueObject\Option;
return (new Config())
->merge(contao_easy_coding_standard())
->setRules([
// Add custom rules here
'@Symplify:CodingStandard' => true,
]);
Fix Automatically
Use --fix to auto-correct issues:
vendor/bin/ecs fix src
Parallel Execution Speed up checks with parallel processing:
vendor/bin/parallel-lint src && vendor/bin/ecs check src --parallel
husky or pre-commit to run ECS before commits.contao/naming for DCA naming conventions).@Symfony or @Doctrine rulesets if your project uses them.Rule Conflicts
Symplify). Test thoroughly after merging rulesets.contao/naming might clash with PSR12 for class naming.Performance
--parallel or exclude tests:
vendor/bin/ecs check src --exclude=tests/
False Positives
no_unused_imports. Exclude legacy directories:
->setExcludedFiles('legacy/*')
Configuration Overrides
->merge(contao_easy_coding_standard()) // Keep defaults
--verbose to diagnose rule failures:
vendor/bin/ecs check src --verbose
vendor/bin/ecs check src --dry-run
Incremental Adoption
Start with a subset of rules (e.g., @contato/basic) and expand gradually.
Document Rules
Add a CODING_STANDARDS.md to your repo explaining ECS rules and exceptions.
Contao-Specific Extensions
contato/naming for DCA field naming consistency.contato/array-syntax for Contao’s array() vs [] preferences.Exclude Vendors
Always exclude vendor/ to avoid false positives:
->setExcludedFiles('vendor/*')
Update Rulesets
Regularly update contao/easy-coding-standard to align with Contao’s latest standards:
composer update contao/easy-coding-standard --dev
How can I help you explore Laravel packages today?