DefaultSet and ExtendedPERSet), which can be adopted to enforce consistent coding standards across teams.phpunit, pint, or laravel-shift.ConfigBuilder, enabling TPMs to override or extend rules for project-specific needs (e.g., legacy codebases or custom PSR standards)..php-cs-fixer.dist.php config file. No database migrations, API changes, or Laravel service provider modifications are needed.cs:diff in PR checks before enforcing fixes).php-cs-fixer.cache) can be excluded from deployments.| Risk Area | Mitigation Strategy |
|---|---|
| Rule Conflicts | Start with cs:diff to preview changes. Use --allow-risky=yes cautiously. |
| Performance Overhead | Cache file (php-cs-fixer.cache) reduces repeated analysis. Exclude from Git. |
| Dependency Bloat | Dev-only dependency; no runtime impact. |
| Rule Drift | Pin wayofdev/cs-fixer-config to a specific version in composer.json. |
| Legacy Code Issues | Use ExtendedPERSet for stricter rules or customize via ConfigBuilder. |
Standard Alignment:
RuleSet (DefaultSet or ExtendedPERSet) aligns closest?cs:diff in CI)?Adoption Strategy:
cs:diff) before requiring auto-fixes (cs:fix).Customization Needs:
->exclude() in ConfigBuilder.DefaultSet for core, ExtendedPERSet for tests)?CI/CD Integration:
Toolchain Conflicts:
pint, prettier)? Define ownership (e.g., CS Fixer for PHP, Prettier for JS).lint-php/lint-diff.Assessment Phase:
composer req --dev wayofdev/cs-fixer-config and vendor/bin/php-cs-fixer fix --dry-run to preview changes.DefaultSet for minimal disruption; ExtendedPERSet for stricter standards.CI Integration:
cs:diff to PR checks (e.g., GitHub Actions, GitLab CI).- name: Run PHP CS Fixer
run: composer cs:diff
Developer Onboarding:
cs:fix to local workflows (e.g., composer.json scripts or Makefile).Enforcement:
cs:fix in CI (e.g., fail builds on violations).->setRiskyAllowed(true) sparingly for high-impact fixes.composer.json constraints).^3.58 (verify compatibility with Laravel’s PHP-CS-Fixer usage).pint, phpstan). Use ConfigBuilder to override conflicting rules:
$config = ConfigBuilder::createFromRuleSet(new DefaultSet())
->setRules([
'@Symfony' => true,
'no_unused_imports' => false, // Disable if conflicting with IDE
]);
Pre-Migration:
cs:diff.->exclude(['legacy/**', 'vendor/**'])
Initial Rollout:
cs:diff in CI (non-blocking).cs:fix to local workflows.Full Enforcement:
Optimization:
php-cs-fixer.cache) to reduce CI runtime.--parallel).wayofdev/cs-fixer-config for updates (e.g., new PHP-CS-Fixer versions).composer.json to avoid surprises:
"wayofdev/cs-fixer-config": "^1.5"
DefaultSet to ExtendedPERSet).return statement on a new line?").php-cs-fixer fix --verbose.--dry-run to isolate problematic files:
vendor/bin/php-cs-fixer fix --dry-run --path-mode=intersection --path=src/Controller.php
--parallel for faster runs.ConfigBuilder to tailor rules per team (e.g., frontend vs. backend).| Scenario | Mitigation |
|---|---|
| CI Timeouts | Cache results (php-cs-fixer.cache) and run in parallel. |
| Rule Overhead | Start with DefaultSet; migrate to stricter rules gradually. |
| Merge Conflicts | Auto-commit fixes in CI (as shown in GitHub Actions example). |
| Legacy Code Rot | Exclude problematic files temporarily; refactor incrementally. |
| Toolchain Conflicts | Audit other formatters (e.g., pint) and align rules. |
How can I help you explore Laravel packages today?