Search by

konradmichalik / php-cs-fixer-preset

konradmichalik

Preset configuration for PHP-CS-Fixer

Package info

github.com/konradmichalik/php-cs-fixer-preset

pkg:composer/konradmichalik/php-cs-fixer-preset

Statistics

Installs: 55 869

Dependents: 10

Suggesters: 0

Stars: 0

Open Issues: 1

0.4.0 2026-11-24 10:59 UTC

This package is auto-updated.

Last update: 2026-12-01 23:52:26 UTC


README

icon

PHP-CS-Fixer Preset

Coverage CGL Tests Supported PHP Versions

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

Packagist Packagist Downloads

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).