craftcms/ecs
Easy Coding Standard (ECS) config presets for Craft CMS projects and plugins. PSR-12 aligned with a few Craft-specific tweaks. Install via Composer, add an ecs.php selecting Craft 3 or 4 set, then run ecs check (optionally --fix).
craftcms/ecs package provides pre-configured PHP Coding Standards (ECS) rules tailored for Craft CMS projects, leveraging the PHP-CS-Fixer ecosystem. This aligns well with teams adopting Laravel (or Laravel-based Craft CMS) who seek consistent code quality without reinventing ECS configurations.craft/app, plugins/) may require adaptation for pure Laravel projects but could still be useful for hybrid Laravel-Craft setups.ecs.php, enabling teams to extend or override Craft-specific rules for Laravel needs.craft/config/general.php) may clash with Laravel’s config/ structure. Mitigation: Test in a staging environment or use --dry-run.--ignore for non-Craft files or lazy-load in CI.app/ or plugins/ directories)?composer execute) or post-merge?php artisan ecs:fix).composer execute to run ECS on pre-commit.craftcms/ecs + php-cs-fixer).config/ vs. craft/config/).vendor/bin/ecs check --dry-run to identify issues.ecs.php to:
return [
'rules' => [
// Override Craft rules for Laravel
\SlevomatCodingStandard\Sniffs\TypeHints\DisallowMixedTypeHintSniff::class,
// Add Laravel-specific rules
\Symplify\CodingStandard\Sniffs\Arrays\ArrayPushOnNewLineSniff::class,
],
'paths' => [
__DIR__.'/app', // Target Laravel directories
// Exclude Craft-specific paths if not used
],
];
composer.json:
"scripts": {
"ecs": "vendor/bin/ecs check src --config=ecs.php",
"ecs:fix": "vendor/bin/ecs fix src --config=ecs.php"
}
php-cs-fixer or phpstan setups.laravel-shift/laravel-coding-standard).composer require --dev craftcms/ecs.ecs.php (copy from vendor/craftcms/ecs/ecs.php and modify).composer ecs in a staging environment to catch issues early.- name: Run ECS
run: composer ecs
composer ecs:fix).ecs.php may diverge from upstream Craft CMS updates.composer update cautiously or pin versions.--verbose flag for detailed output.## ECS Rules
- Run `composer ecs` to check code.
- Fix issues with `composer ecs:fix`.
- Exclude paths: Add to `ecs.php` under `paths`.
--parallel or exclude large directories (e.g., storage/).ecs --parallel for multi-core processing..ecsignore.| Failure Scenario | Impact | Recovery |
|---|---|---|
| ECS blocks CI pipeline | Delays releases | Configure as a warning or auto-fix. |
| Rule conflicts with Laravel | False positives/negatives | Override rules in ecs.php. |
| Outdated package version | Broken rules or security risks | Pin versions in composer.json. |
| High false-positive rate | Developer frustration | Adjust rule severity or exclude paths. |
pre-commit checks for immediate feedback.How can I help you explore Laravel packages today?