m6web/php-cs-fixer-config
Reusable PHP CS Fixer configuration from M6Web/Bedrock Streaming. Install via Composer and use the provided BedrockStreaming config in .php-cs-fixer.dist.php, with options to extend/override rules for your project or CI.
Pros:
.php-cs-fixer.cache, improving pipeline performance..gitignore rules prevent cache pollution, keeping repositories clean.Cons:
use App\ ordering, facade imports). Requires manual overrides.native_function_invocation or declare_strict_types may break legacy code unless explicitly configured.composer require --dev m6web/php-cs-fixer-config)..php-cs-fixer.dist.php) with path adjustments for src//tests/.Makefile for CI/CD integration (3 commands: cs, cs-fix, cs-ci).php-cs-fixer CLI).| Risk | Mitigation Strategy |
|---|---|
| Rule Conflicts | Use --dry-run to preview changes before enforcement. Customize rules via inheritance. |
| Performance in CI | Enable caching (--using-cache=yes) and parallelize checks. |
| False Positives | Override rules in .php-cs-fixer.dist.php (e.g., disable no_superfluous_phpdoc_tags for legacy PHPDoc). |
| Breaking Changes | Pin PHP-CS-Fixer version in composer.json to avoid unexpected rule updates. |
| IDE Integration Gaps | Pair with PHPStorm/VSCode plugins or document CLI workflows for real-time fixes. |
ordered_imports, no_unused_imports) be added to the base config?if: always()), or be warnings?^5.1 or ~5.1.0 in composer.json?artisan format)?native_function_invocation, declare_strict_types).composer.json structure.php artisan cs:fix) for Laravel-native workflows.php-cs-fixer CLI.
# Example GitHub Actions workflow
jobs:
cs-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: composer install
- run: make cs-ci # Uses the provided Makefile target
pre-commit frameworks:
# .husky/pre-commit
- **IDE Support**: Configure PHPStorm/VSCode to use the config file for real-time fixes:
- **PHPStorm**: Set `.php-cs-fixer.dist.php` in `Settings > PHP > Code Sniffer`.
- **VSCode**: Use the `PHP CS Fixer` extension with the config path.
$rules = (new M6Web\CS\Config\BedrockStreaming())->getRules();
$rules['ordered_imports'] = true;
$rules['no_unused_imports'] = true;
$rules['single_blank_line_before_namespace'] = true;
return $rules;
Phase 1: Assessment (1–2 Days)
composer require --dev m6web/php-cs-fixer-config
cp vendor/m6web/php-cs-fixer-config/.php-cs-fixer.dist.php.example .php-cs-fixer.dist.php
make cs # Checks for violations without fixing
Phase 2: Customization (2–5 Days)
$rules = (new M6Web\CS\Config\BedrockStreaming())->getRules();
$rules['risky_allowed'] = false; // Disable risky rules by default
$rules['native_function_invocation'] = ['scope' => 'namespaced']; // Customize scope
make cs-fix --path=src/App/Http/Controllers
Phase 3: CI/CD Integration (1–3 Days)
cs-ci target to your CI pipeline (see Stack Fit for examples).- name: PHP CS Fixer
run: make cs-ci
if: always() # Run even if tests fail
Phase 4: Developer Onboarding (Ongoing)
Makefile to the project template:
cs: ./vendor/bin/php-cs-fixer fix --dry-run --diff
cs-fix: ./vendor/bin/php-cs-fixer fix
cs-ci: ./vendor/bin/php-cs-fixer fix --dry-run --using-cache=no --verbose
CONTRIBUTING.md:
## Code Style
Ensure your changes pass PHP CS Fixer:
```bash
make cs # Check for violations
make cs-fix # Auto-fix violations
make cs locally before commits.How can I help you explore Laravel packages today?