eliashaeussler/php-cs-fixer-config
Reusable PHP-CS-Fixer config package by Elias Häussler. Provides a ready-to-use ruleset and sensible defaults to keep PHP code style consistent across projects, with easy installation and quick integration into existing fixer setups.
composer require --dev eliashaeussler/php-cs-fixer-config
.php-cs-fixer.php in your project root to import the config:
<?php
use Eliashaeussler\PhpCsFixerConfig\Config;
return (new Config())
->setRiskyAllowed(true)
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__)
->name('*.php')
->ignoreDotFiles(true)
->ignoreVCS(true)
);
./vendor/bin/php-cs-fixer fix
--dry-run and --diff.💡 First use case: Enforce consistent formatting across a new Laravel app without manually configuring rules — just install and run.
Centralized Standard: Add this as a dev dependency in a shared internal Composer repository or monorepo root (e.g., via composer require --dev your-org/standard-config). All child projects inherit the same style rules.
Project-Level Customization: Extend or override rules in your .php-cs-fixer.php:
$config = new Config();
$config->setRules([
'class_attributes_separation' => true,
'multiline_whitespace_before_semicolons' => false, // disable risky rule
'native_function_invocation' => ['include' => ['@all']],
]);
return $config;
CI Integration: Use in GitHub Actions/GitLab CI:
- name: Run PHP-CS-Fixer
run: ./vendor/bin/php-cs-fixer fix --dry-run --diff
Pre-commit Hook: Combine with husky or git hooks to auto-fix on commit:
vendor/bin/php-cs-fixer fix --allow-risky=yes
setRiskyAllowed(true) is required for many modern rules (e.g., native_function_invocation) — don’t forget this if fixes don’t apply.
Rule conflicts: If you override rules, check for overlaps (e.g., php_unit_strict may conflict with strict in general). Use ./vendor/bin/php-cs-fixer describe <rule> to inspect behavior.
Version locking: Pin the package version ("eliashaeussler/php-cs-fixer-config": "^1.2") to avoid unexpected style changes from updates — use patch versions for safety.
Performance tip: Use Finder with notPath() to exclude vendor, cache, and generated dirs:
->notPath('bootstrap/cache')
->notPath('storage')
Debugging fix issues: Run with --using-cache=no and --stop-on-violation to pinpoint which file(s) break the build.
Extensibility: You can subclass Config and override methods like getRules() if you need complex, dynamic rule composition across contexts (e.g., Laravel vs. API-only).
How can I help you explore Laravel packages today?