corpus / php-cs-fixer-config
Shared PHP-CS-Fixer configuration for Corpus projects.
Requires
- php: ^7.4 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0 || ~8.6.0
- friendsofphp/php-cs-fixer: ^3.95
Requires (Dev)
- corpus/coding-standard: ^0.10
- phpunit/phpunit: ^9.6 || ^11.0
- squizlabs/php_codesniffer: ^4.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-26 20:05:19 UTC
README
This package shares the PHP-CS-Fixer rules used by Corpus projects. It does not choose files to fix. Each project owns its own Finder.
Requirements
- PHP 7.4, or PHP 8.0 through 8.6
- PHP-CS-Fixer 3.95 or later
Installation
Install the package as a development dependency:
composer require --dev corpus/php-cs-fixer-config
friendsofphp/php-cs-fixer is a package dependency because the factory creates
its PhpCsFixer\Config object. It is not a production dependency of consuming
applications because this package is installed with --dev.
Usage
Create .php-cs-fixer.dist.php in the consuming project:
<?php use Corpus\PhpCsFixer\Config; use PhpCsFixer\Finder; return Config::php7x4() ->setFinder( Finder::create()->in(__DIR__ . '/src'), );
Choose a factory for the lowest PHP version supported by the project:
Config::php7x4()Config::php8x1()Config::php8x2()Config::php8x5()
The factory preserves the shared rules and enables risky rules. It uses tabs, Unix line endings, and the standard PHP-CS-Fixer cache. Each version adds only rules that are safe for that PHP target.
Project-specific overrides
Use PHP-CS-Fixer's normal API after creating the configuration:
<?php use Corpus\PhpCsFixer\Config; use PhpCsFixer\Finder; $config = Config::php8x2(); return $config ->setRules([ ...$config->getRules(), 'ordered_imports' => false, ]) ->setFinder(Finder::create()->in(__DIR__));
Updating
Update this package with Composer. Then run PHP-CS-Fixer in each consuming project and review the resulting formatting changes before committing them.
composer update corpus/php-cs-fixer-config
composer exec php-cs-fixer fix -- --diff
Rule changes can reformat existing files. Pin a release version in projects that need controlled upgrades.
Development
The package checks its own code with Corpus Coding Standard. Run all checks with:
make test
The package itself uses the PHP 7.4 configuration. This keeps the distributed source compatible with the package minimum PHP version.
Apply automatic fixes with Corpus Coding Standard and PHP-CS-Fixer:
make fix
The Composer plugin installs the Coding Standard for PHP_CodeSniffer.