From PHP CS Fixer to DressCode
The @PSR12, @PER-CS and @Symfony sets have matching standards in
DressCode, and dresscode migrate config translates your whole .php-cs-fixer.dist.php into
dresscode.neon. Instead of fixers and their options, you then write how the code should look: where PHP CS Fixer
needs two fixers and six options for the backslash before global names, one section is enough here. And many risky rules are not
risky here, because the syntax tree tells the safe case from the unsafe one.
DressCode as an Alternative to PHP CS Fixer
In daily work, little changes: check takes the place of fix --dry-run, and fix stays
fix. What you gain: the same dresscode fix can also upgrade the code to a newer PHP and to new versions
of Nette, Symfony or Laravel.
After PHP CS Fixer formatted Laravel with its set for PER Coding Style, DressCode still found 1,201 places where the code does not follow the standard, and 7,497 in Symfony 3.4. Part of the difference comes from the versions: PHP CS Fixer implements PER Coding Style 3.0, DressCode 3.1. In the other direction, PHP CS Fixer changed 9 places in Laravel after DressCode; the comparison explains where they come from. Measured in October 2026 with PHP CS Fixer 3.95.
For a project that has to stay on PHP 7, PHP CS Fixer is the better choice: it runs on PHP 7.4. DressCode needs PHP 8.4 to run and checks code written for PHP 8.0 or newer.
Before You Start
The common steps apply to every tool; this page covers only what is different with PHP CS Fixer.
The main thing first: the configuration of PHP CS Fixer is a PHP file that has to be executed, and it returns an object
of its library. So the dresscode migrate config command runs it in a process of its own, with the autoloader of the
project loaded, and whatever the file prints or does stays in that process. DressCode itself may be installed anywhere, but PHP CS
Fixer must still be in the project: in vendor/ as a dependency, as a phar from phive in
tools/php-cs-fixer, as the package php-cs-fixer/shim, or installed by Composer on its own in
tools/ or vendor-bin/. The file runs only for the rules; DressCode reads the paths from its code without
running it. When the classes of PHP CS Fixer are missing, migrate config stops with a configuration error and exit
code 3:
Error: File `/var/www/shop/.php-cs-fixer.dist.php` needs the classes of PHP CS Fixer, which DressCode finds neither in `vendor/` nor in `tools/`: Class "PhpCsFixer\Finder" not found.
So convert the configuration before you remove PHP CS Fixer from the project.
Converting the Configuration
dresscode migrate config .php-cs-fixer.dist.php
Sets are translated to standards: @PSR1, @PSR2 and @PSR12 to psr12;
@PER, @PER-CS and their numbered variants to perCs, which matches PER Coding Style 3.1; and
@Symfony to symfony, which does not have most of the phpDoc rules yet. migrate config
reports sets with no counterpart and tells you where to start; for @PhpCsFixer it is symfony. Sets with
the :risky suffix have no counterpart, because here risky fixes are not turned on by a set, but by the project for
individual decisions (see below).
Fixers are translated to decisions, together with their options where an option has a counterpart. A configuration with the
@PER-CS set, the no_unused_imports fixer and trailing_comma_in_multiline with
elements for arrays, arguments and parameters gives this dresscode.neon:
use: [perCs]
imports:
unused: forbidden
multiline:
trailingComma:
array: required
argument: required
parameter: required
matchArm: optional
closureUse: optional
import: optional
list: optional
classes:
instantiationWrapping: keep
no_unused_imports is imports.unused, which,
like the fixer, also counts a name in phpDoc as a use. trailing_comma_in_multiline was split into the multiline.trailingComma keys, one for each place where a
comma can go; what elements did not list got optional, which means the comma is left as the author
wrote it.
migrate config added classes.instantiationWrapping: keep by itself: from PHP 8.4, the
perCs standard writes new Foo()->bar() without parentheses around new, while the
@PER-CS set leaves them as they are. A fixer with no counterpart is listed in the block at the end of the generated
file, and that gives you a list of things you need to decide about. Custom fixers from the
kubawerlos/php-cs-fixer-custom-fixers package are translated too, as long as DressCode knows the construct they deal
with. Which decision matches which fixer is listed in the table of PHP CS
Fixer rules.
What migrate config does not carry over, because in the Fixer configuration these are not rules:
- The Finder, beyond its paths.
migrate configreadsin(),exclude(),notPath(),notName()andappend()with a literal or__DIR__from the code of the configuration and writes them topathsandexcludePathsby itself. It addsfilter(),depth()and the other conditions of the Finder to the notes at the end of the file, and so it does with a call whose argument cannot be read without running it, such asin($dirs); rewrite those by hand. The patterns are described in Configuration. - Indentation and line endings (
setIndent(),setLineEnding()). The standard sets them. If you use none, add the decisionsindentation.unitandfile.lineEnding; without a standard,migrate configreminds you of them by itself. setRiskyAllowed(true). DressCode does not give permission for risky fixes to the whole configuration, but to individual decisions: their paths go in thefixRiskylist. Without that list, risky fixes are only reported.
One Thing, One Key
In PHP CS Fixer, several rules share one construct, and the result comes from how they work together. A project using PER
Coding Style that wants to write global classes with a backslash, \Exception, and functions without one, except those
PHP can optimize, needs two fixers and six options, and one of the options means the opposite of what it seems to say:
import_classes => false does not mean “do not import”, but “rewrite imported classes to the fully qualified
name”. On top of that, it needs no_unused_imports, so that the imports left over after the rewrite disappear:
$config->setRules([
'@PER-CS' => true,
'native_function_invocation' => [
'include' => ['@compiler_optimized'],
'scope' => 'namespaced',
'strict' => true,
],
'global_namespace_import' => [
'import_classes' => false,
'import_constants' => false,
'import_functions' => false,
],
'no_unused_imports' => true,
]);
In DressCode, these are keys of one section, qualification, and each one names what it wants;
imports.unused removes the unused imports:
use: perCs
qualification:
class:
global: backslashed
function:
global: bare
optimized: backslashed
imports:
unused: forbidden
From this code:
<?php
namespace App\Model;
use DateTimeImmutable;
use InvalidArgumentException;
class Cart
{
public function add(array $items, string $sku): DateTimeImmutable
{
if (strlen($sku) === 0 || in_array($sku, $items, true)) {
throw new InvalidArgumentException('Invalid SKU');
}
return new DateTimeImmutable(\date('Y-m-d'));
}
}
both tools make this:
<?php
namespace App\Model;
class Cart
{
public function add(array $items, string $sku): \DateTimeImmutable
{
if (\strlen($sku) === 0 || in_array($sku, $items, true)) {
throw new \InvalidArgumentException('Invalid SKU');
}
return new \DateTimeImmutable(date('Y-m-d'));
}
}
Except for one place: PHP CS Fixer qualifies in_array($sku, $items, true), because in_array is in the
@compiler_optimized list, while DressCode leaves it bare, because the compiler speeds up only a search in an array
written directly in the code, not in a variable. DressCode decides by the call, not by the name. It removes the backslash from
date() without risk when the configuration says nameResolution: certain, that is, that no namespace of
the project declares a function date(); otherwise it is a risky fix, just as native_function_invocation
is a risky fixer. The rest of the section, constants and imports of global names, is described in How Global Names Are Written.
Risky Rules
PHP CS Fixer marks a rule as risky when, on an array of tokens, it cannot tell a safe case from a dangerous one, and it leaves
the decision to you. A typical example is ternary_to_elvis_operator: it cannot tell whether the condition of a
ternary operator is a variable or a function call with a side effect, so it watches only for ++ and --,
and the rest is up to you.
DressCode does not have this split, because the tree answers the question: the decision expressions.ternary.short shortens a ternary operator only
when the condition is safe to evaluate twice, and it leaves a function call alone. The same goes for other rules that were risky
for the same reason.
Fixes that can change the behavior of the program are a different thing. DressCode does not turn them on with a special set. It
reports them as risky, place by place, and for each one it says what would decide it: mistakes.strictArgument adds
the parameter $strict = true to in_array() right away where the types from PHPStan say an integer is searched for among integers, and elsewhere
it only reports the fix as risky. A risky fix is made only when you list its decision in the fixRisky list in the
configuration, or for one run with --fix-risky; until then it is a warning where types would decide it, and an error
where it changes behavior by its nature, like adding declare(strict_types=1). Writing a decision that changes the
meaning of code, like expressions.comparison.loose: forbidden, does not yet mean you agree with its fixes; you agree
only by listing it in fixRisky.
Some fixers form a special group, such as is_null, no_alias_functions and dir_constant:
PHP CS Fixer marks them as risky because someone could declare a function of the same name in a namespace. In DressCode, the
configuration settles this doubt. With the nameResolution: certain key and the lists in the namespaces
key, DressCode knows what is in your namespaces, and the corresponding fixes are safe; see Functions and Constants in Namespaces.
Commands
| PHP CS Fixer | DressCode |
|---|---|
php-cs-fixer fix --dry-run |
dresscode check |
php-cs-fixer fix --dry-run --diff |
dresscode check --diff |
php-cs-fixer fix |
dresscode fix |
php-cs-fixer fix --config=file |
dresscode fix --config file |
php-cs-fixer fix --rules=name |
dresscode fix --set path=value, which adds the decision to the configuration, or
dresscode fix --only path, which runs only the ones you name |
php-cs-fixer fix src --rules=@PSR12 |
dresscode fix src --use psr12 in a project without a configuration |
php-cs-fixer fix --format=checkstyle |
dresscode check -f checkstyle |
php-cs-fixer fix --allow-risky=yes |
dresscode fix --fix-risky; permanently, a list of decisions in the fixRisky key |
php-cs-fixer describe name |
dresscode explain path |
.php-cs-fixer.cache |
the cache is on by itself; --no-cache bypasses it |
The exit code of PHP CS Fixer is a bit mask (8 means violations found, 16 a configuration error, and so on), while DressCode has one scale for every command, see Exit Codes. A CI script that evaluated the mask needs one change.
What PHP CS Fixer Did Not Have
- PER Coding Style 3.1. PHP CS Fixer implements version 3.0 (the
@PER-CS3x0set), while theperCsstandard implements version 3.1. The places DressCode still finds after PHP CS Fixer (the numbers are at the top of this page) are places where PER Coding Style wants one item per line, a heredoc indented with the surrounding code, or a comma after a multiline list, see the comparison. - A message at every place, including what the fix can change. For a file,
php-cs-fixer fix --dry-run -vprints the names of the fixers that would change it, and with--diffthe change itself; thecheckstyleformat has one entry per fixer and file, with no line number.php-cs-fixer describeexplains why a fixer is risky, once for all places; forstrict_param, it saysRisky when the fixed function is overridden or if the code relies on non-strict usage.With--allow-risky=yesit then addstrueto everyin_array(), without it to none. DressCode judges each call separately and says why a risky one is risky, as Risky Rules shows. The same output also shows an overriding method whose parameter is named differently than in the parent, and a call to a method the library marked as deprecated; PHP CS Fixer reports neither of them, not even with the@PhpCsFixer:riskyand@Symfony:riskysets. The full output is shown on the home page. - Suppressing on a line. PHP CS Fixer cannot turn off a rule for one line or for a block, only for a whole file through
the Finder. Here you have
// dresscode:ignore pathfor that, and the pairdresscode:disableanddresscode:enable, see Suppressions and the Baseline. - Different values for part of the project are written as an override in the
overrideskey, with no second configuration file; a decision there gets a different value, orkeep, see Configuration. - Trying a decision without losing your configuration. In PHP CS Fixer,
--rulesreplaces the rules from the configuration file, so a fixer you try runs without the rest of your set and with default options, unless you spell out others in JSON. In DressCode,dresscode fix --set path=valueadds the decision to the rest of the configuration, so its changes come out already formatted by your standard, see Configuration. - Baseline. A decision that your code does not meet yet, and that cannot be fixed for you, can be turned on right away:
the
dresscode baselinecommand records today's violations, and only new ones will be reported. PHP CS Fixer does not have one; how DressCode combines it with fixes is described in Baseline. - Your own rule is written against the tree, not against tokens. The tutorial takes one afternoon, and if you have a custom fixer, a separate page shows how to port it.
What is different for every tool is summed up in the common steps.