composer require bitbag/coding-standard --dev
ecs.php):
<?php
declare(strict_types=1);
use Symplify\EasyCodingStandard\Config\ECSConfig;
return static function (ECSConfig $config): void {
$config->import('vendor/bitbag/coding-standard/ecs.php');
$config->paths(['src', 'tests']);
};
phpstan.neon):
includes:
- vendor/bitbag/coding-standard/phpstan.neon
./vendor/bin/ecs check src
./vendor/bin/phpstan analyse src
Run a pre-commit hook to enforce standards before merging:
./vendor/bin/ecs check src --fix
git add .
git commit -m "Enforce coding standards"
Automate Checks:
composer.json:
"scripts": {
"cs-check": "ecs check src --fix",
"cs-fix": "ecs check src --fix --diff",
"phpstan": "phpstan analyse src"
}
composer cs-check
CI/CD Integration:
- name: Run ECS
run: ./vendor/bin/ecs check src --no-cache
- name: Run PHPStan
run: ./vendor/bin/phpstan analyse src --level=8
Customize Rules:
$services = $config->services();
$services->set(\Your\Custom\Fixer::class);
parameters:
level: max
paths:
- { path: src, level: 8 }
- { path: tests, level: 5 }
Team Onboarding:
CONTRIBUTING.md:
## Coding Standards
- Run `composer cs-fix` before PRs.
- PHPStan level 8 for `src/`, level 5 for `tests/`.
ECS Fixes Fail Silently:
--debug to diagnose:
./vendor/bin/ecs check src --fix --debug
Undefined constant "T_TYPE_CLOSE_PARENTHESIS" → Update ECS/Symfony versions.PHPStan False Positives:
// @phpstan-ignore-next-line
$result = $this->someUnsafeMethod();
phpstan.neon:
excludeFiles:
- 'tests/Integration/UnstableTest.php'
BitBag Header Injection:
putenv('ALLOW_BITBAG_OS_HEADER=0')
ecs.php:
$config->paths(['src', 'tests'])->exclude(['vendor/', 'config/']);
Incremental Fixing:
--diff to see only changed files:
./vendor/bin/ecs check src --fix --diff
PHPStan Parallel Analysis:
./vendor/bin/phpstan analyse tests --parallel
Custom Rule Validation:
$config->ruleWithConfiguration(
\SlevomatCodingStandard\Sniffs\TypeHints\TypeHintSniff::class,
['type_hint_types' => ['array', 'iterable']]
);
IDE Integration:
Settings > PHP > Quality Tools > PHPStanConfiguration File to phpstan.neon.Performance:
./vendor/bin/ecs check src --cache
Legacy Code:
$config->paths(['src'])->skip(['legacy/']);
```markdown
### Debugging Checklist
1. **ECS Issues**:
- [ ] Run with `--debug` flag.
- [ ] Check Symfony/ECS version compatibility.
- [ ] Verify `paths()` include/exclude logic.
2. **PHPStan Issues**:
- [ ] Test with `--level=max` to isolate errors.
- [ ] Check for `@phpstan-ignore` misuse.
- [ ] Validate `phpstan.neon` includes/excludes.
3. **Environment**:
- [ ] Ensure `ALLOW_BITBAG_OS_HEADER` is set correctly.
- [ ] Confirm PHP version matches package requirements (^8.1).
How can I help you explore Laravel packages today?