konradmichalik / php-cs-fixer-preset
Preset configuration for PHP-CS-Fixer
Package info
github.com/konradmichalik/php-cs-fixer-preset
pkg:composer/konradmichalik/php-cs-fixer-preset
Requires
- php: ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0 || ~8.6.0
- ext-ctype: *
- friendsofphp/php-cs-fixer: ^3.92
- symfony/finder: ^5.4 || ^6.0 || ^7.0 || ^8.0
Requires (Dev)
- armin/editorconfig-cli: ^2.0
- ergebnis/composer-normalize: ^2.44
- konradmichalik/php-doc-block-header-fixer: ^0.4.0
- phpstan/phpstan: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-symfony: ^2.0
- phpunit/phpunit: ^11.0 || ^12.0 || ^13.0
- rector/rector: ^2.2
- typo3/coding-standards: ^0.9
Suggests
- typo3/coding-standards: Required to use the TYPO3RuleSet
Provides
None
Conflicts
None
Replaces
None
README
PHP-CS-Fixer Preset
This package provides a basic PHP-CS-Fixer configuration.
Important
This package is intended for use in my personal projects only. It is not designed for general use.
🔥 Installation
composer require konradmichalik/php-cs-fixer-preset --dev
⚡ Usage
Configure PHP-CS-Fixer in your .php-cs-fixer.php file:
use KonradMichalik\PhpCsFixerPreset\Config; use KonradMichalik\PhpCsFixerPreset\Package\{Author, CopyrightRange, Type}; use KonradMichalik\PhpCsFixerPreset\Rules\Header; use KonradMichalik\PhpCsFixerPreset\Rules\Set\RuleSet; use Symfony\Component\Finder\Finder; return Config::create() // Header Comment Rule with manual data ->withRule( Header::create( 'php-cs-fixer-preset', Type::ComposerPackage, Author::create('Konrad Michalik', 'hej@konradmichalik.dev'), CopyrightRange::from(2025), ), ) // Header Comment Rule with Composer Detection ->withRule( Header::fromComposer( __DIR__.'/composer.json', copyrightRange: CopyrightRange::from(2025) // Optional overwrite specific composer information ), ) // Custom Rule ->withRule( RuleSet::fromArray([ 'modernize_types_casting' => true, ]), ) ->withFinder(static fn (Finder $finder) => $finder->in(__DIR__)) ;
Tip
Pass detectLicense: true to Header::fromComposer() to render the license text for GPL-2.0-or-later, GPL-3.0-or-later and proprietary packages based on the license field in composer.json.
Note
The default finder only matches PHP files, honors .gitignore and skips directories named vendor and node_modules at any depth. Adjust it with withFinder().
Note
withRule() and RuleSet::add() merge on rule level: a rule's configuration replaces any previous configuration of the same rule completely. Pass the full option set when overriding a configured rule.
🧩 TYPO3
TYPO3RuleSet applies the rules of typo3/coding-standards, which has to be installed separately:
composer require typo3/coding-standards --dev
By default Config::create() starts with the DefaultSet, so the TYPO3 rules are merged on top of it and @Symfony and @Symfony:risky stay active:
use KonradMichalik\PhpCsFixerPreset\Config; use KonradMichalik\PhpCsFixerPreset\Rules\Set\TYPO3RuleSet; return Config::create() ->withRule(TYPO3RuleSet::create()) ;
To apply the TYPO3 rules only, skip the DefaultSet and replace the rules instead of merging them. Without merge: false, the @PSR12 rule set of PHP-CS-Fixer's own default config would stay active:
return Config::create(skipDefaultSet: true) ->withRule(TYPO3RuleSet::create(), merge: false) ;
🚫 Rejected rules
Evaluated in a dry run over 24 repositories and left out of the DefaultSet on purpose:
| Rule | Reason |
|---|---|
PedroTroller/useless_code_after_return |
Deletes live code after braceless if (...) return; |
PhpCsFixerCustomFixers/no_nullable_boolean_type |
Breaks tri-state flags such as ?bool $flag = null |
strict_comparison, strict_param |
Change runtime behavior |
mb_str_functions |
Byte semantics are intended in places |
PhpCsFixerCustomFixers/isset_to_array_key_exists |
Different semantics for null values |
PhpCsFixerCustomFixers/phpdoc_no_incorrect_var_annotation |
Removes @var narrowing that PHPStan relies on |
PhpCsFixerCustomFixers/no_useless_dirname_call |
Turns dirname(__DIR__, 3) into __DIR__.'/../../..' |
numeric_literal_separator |
Rewrites exception codes and breaks searching for them |
PhpCsFixerCustomFixers/no_useless_comment |
Removes the summary lines added by php-doc-block-header-fixer |
multiline_promoted_properties, string_implicit_backslashes |
Style churn without a defect behind it |
ErickSkrauch/*, PedroTroller/line_break_between_method_arguments |
Layout only |
PhpCsFixerCustomFixers/typed_class_constant requires PHP 8.3 and is deferred until it is the minimum version.
💎 Credits
This project is highly inspired by the fabulous php-cs-fixer-config package by Elias Häußler.
⭐ License
This project is licensed under GNU General Public License 3.0 (or later).