prooph/php-cs-fixer-config
Shared PHP-CS-Fixer configuration from the prooph team. Provides a ready-to-use ruleset and presets to keep PHP code style consistent across projects, with an easy way to apply and maintain formatting standards in CI or local development.
Installation Add the package to your project via Composer:
composer require --dev prooph/php-cs-fixer-config
Ensure php-cs-fixer is also installed:
composer require --dev friendsofphp/php-cs-fixer
First Use Case Run PHP CS Fixer with the Prooph config in your project root:
vendor/bin/php-cs-fixer fix --config=vendor/prooph/php-cs-fixer-config/php-cs-fixer.dist.php
For a dry run (check without fixing):
vendor/bin/php-cs-fixer fix --dry-run --config=vendor/prooph/php-cs-fixer-config/php-cs-fixer.dist.php
Where to Look First
vendor/prooph/php-cs-fixer-config/php-cs-fixer.dist.php to understand Prooph’s coding standards (e.g., PSR-12 with Prooph-specific rules).Integrate into CI/CD Add PHP CS Fixer to your pipeline (e.g., GitHub Actions, GitLab CI) to enforce consistency:
# Example GitHub Actions step
- name: Run PHP CS Fixer
run: vendor/bin/php-cs-fixer fix --config=vendor/prooph/php-cs-fixer-config/php-cs-fixer.dist.php --diff
Customize the Config
Extend the Prooph config in your project’s php-cs-fixer.dist.php:
<?php
return (new PhpCsFixer\Config())
->setRules([
// Override or add rules (e.g., enable `no_unused_imports`)
'@Prooph' => true,
'no_unused_imports' => true,
])
->setRiskyAllowed(true); // Enable risky fixes if needed
Pre-Commit Hook
Use tools like php-cs-fixer or husky to run checks before commits:
composer require --dev drupol/php-cs-fixer
Configure in .php-cs-fixer.dist.php or .huskyrc.
Team Onboarding
Document the config in your CONTRIBUTING.md:
## Code Style
Run `composer cs-fix` to auto-fix style issues using Prooph’s config.
composer run cs-fix && composer run stan
vendor/bin/php-cs-fixer fix src/ --config=vendor/prooph/php-cs-fixer-config/php-cs-fixer.dist.php
vendor/ and Laravel-specific files (e.g., bootstrap/cache/*) in the config:
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__)
->exclude('vendor')
->exclude('bootstrap/cache')
)
Rule Conflicts
no_unused_imports). Test thoroughly after merging configs.--dry-run to preview changes before applying.Performance
vendor/bin/php-cs-fixer fix --cache=no --config=...
--parallel for multi-core processing (if supported by your PHP CS Fixer version).Risky Fixes
concat_space) are marked as "risky" and may change logic unintentionally.--diff and disable risky rules if needed:
->setRiskyAllowed(false)
Config Overrides
@Prooph) may break consistency.return (new PhpCsFixer\Config())->setRules(['@Prooph' => true, ...]);
Unexpected Fixes: If CS Fixer modifies code unexpectedly, check the rule docs for side effects.
ordered_imports may reorder use statements aggressively.Cache Issues: Clear the cache if fixes aren’t applied:
rm -rf ~/.cache/php-cs-fixer
Custom Rules Add Prooph-specific rules by extending the config:
->setRules([
'@Prooph' => true,
'prooph_class_alignment' => true, // Hypothetical Prooph rule
])
Path Aliases
If using path aliases (e.g., App\ → app/), configure the finder:
->setFinder(
PhpCsFixer\Finder::create()
->in(['src', 'app'])
->append([__DIR__.'/stubs'])
)
Version Pinning
Pin prooph/php-cs-fixer-config to a specific version in composer.json to avoid unexpected updates:
"require-dev": {
"prooph/php-cs-fixer-config": "1.2.0"
}
Git Attributes
Use .gitattributes to enforce CS Fixer on specific files:
*.php diff=phpcsfixer
Then configure Git to run CS Fixer on diffs.
How can I help you explore Laravel packages today?