• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

dg / dresscode / 41044778467

30 Oct 2026 10:08AM UTC coverage: 97.234% (-0.3%) from 97.495%
41044778467

push

github

dg
upgrade: a decision only the data of the target version turn on belongs to the jump, the project as it is today resolved without narrowing, so that the plan no longer fixes it in the bridge, where nothing runs it

837123ff-7353-45e9-8cd7-ba68b373e93e

5 of 5 new or added lines in 1 file covered. (100.0%)

160 existing lines in 33 files now uncovered.

27315 of 28092 relevant lines covered (97.23%)

0.97 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.24
/src/Config/CorePlugin.php
1
<?php declare(strict_types=1);
2

3
/**
4
 * This file is part of the DressCode, a coding style and upgrade tool for PHP (https://dresscode.run)
5
 * Copyright (c) 2026 David Grudl (https://davidgrudl.com)
6
 */
7

8
namespace DressCode\Config;
9

10
use DressCode\Analyses\IndentationPlan;
11
use DressCode\{Decision, DecisionKind, Domain, Plugin, PluginManifest, Rules, Violation};
12
use DressCode\Domains\{Count, Flag, GrammarEntry, Map, Names, Shapes, Words};
13
use DressCode\Rules\Upgrading\{AttributeForMemberEntry, AttributeTarget, CallTemplate, MemberTarget};
14
use DressCode\Upgrading\{MemberMapGrammar, MemberPattern};
15
use Nette\Schema\{Context, Expect, Schema};
16
use function dirname;
17

18

19
/**
20
 * What the core of DressCode brings: its presets, its rules, whose pages are on dresscode.run, and the decisions no
21
 * single rule of it owns.
22
 * @internal
23
 */
24
final class CorePlugin implements Plugin
25
{
26
        /**
27
         * The presets that are complete standards, the first of them the one taken where the code fits several equally; the
28
         * other presets are sets.
29
         */
30
        public const Standards = ['perCs', 'psr12', 'nette', 'symfony', 'laravel'];
31
        private const QualifiedName = '\\\\?\w+(\\\\\w+)*';
32

33

34
        public function getManifest(): PluginManifest
35
        {
36
                // built once, the grammars of the maps above all, since nothing of it changes
37
                static $manifest;
1 ✔
38
                return $manifest ??= new PluginManifest(
1 ✔
39
                        presets: [
40
                                'dresscode/perCs' => dirname(__DIR__) . '/Presets/perCs.neon',
1 ✔
41
                                'dresscode/psr12' => dirname(__DIR__) . '/Presets/psr12.neon',
1 ✔
42
                                'dresscode/nette' => dirname(__DIR__) . '/Presets/nette.neon',
1 ✔
43
                                'dresscode/symfony' => dirname(__DIR__) . '/Presets/symfony.neon',
1 ✔
44
                                'dresscode/laravel' => dirname(__DIR__) . '/Presets/laravel.neon',
1 ✔
45
                                'dresscode/cleanup' => dirname(__DIR__) . '/Presets/cleanup.neon',
1 ✔
46
                                'dresscode/compilerOptimizations' => dirname(__DIR__) . '/Presets/compilerOptimizations.neon',
1 ✔
47
                                'dresscode/correctness' => dirname(__DIR__) . '/Presets/correctness.neon',
1 ✔
48
                                'dresscode/deprecations' => dirname(__DIR__) . '/Presets/deprecations.neon',
1 ✔
49
                                'dresscode/modernizations' => dirname(__DIR__) . '/Presets/modernizations.neon',
1 ✔
50
                                'dresscode/types' => dirname(__DIR__) . '/Presets/types.neon',
1 ✔
51
                        ],
52
                        rules: [
53
                                Rules\Arrays\ArraySyntaxRule::class,
1 ✔
54
                                Rules\Arrays\MultilineArrayRule::class,
55
                                Rules\Arrays\NoFloatArrayKeysRule::class,
56
                                Rules\Arrays\NoManualListTestsRule::class,
57
                                Rules\Arrays\NoNullArrayKeysRule::class,
58
                                Rules\Arrays\SpreadForArrayMergeRule::class,
59
                                Rules\Arrays\TrailingCommaRule::class,
60
                                Rules\Classes\ClassConstantForConstantCallRule::class,
61
                                Rules\Classes\ClassHeadSpacingRule::class,
62
                                Rules\Classes\ClassKeywordForStringRule::class,
63
                                Rules\Classes\ClassKindInNameRule::class,
64
                                Rules\Classes\ClassNameNotationRule::class,
65
                                Rules\Classes\FinalForInternalClassRule::class,
66
                                Rules\Classes\MemberOrderRule::class,
67
                                Rules\Classes\ModifierOrderRule::class,
68
                                Rules\Classes\MultilineImplementsRule::class,
69
                                Rules\Classes\NameCasingRule::class,
70
                                Rules\Classes\NoConstructorReturnValuesRule::class,
71
                                Rules\Classes\NoDynamicPropertiesRule::class,
72
                                Rules\Classes\NoFinalParentRule::class,
73
                                Rules\Classes\NoGroupedDeclarationsRule::class,
74
                                Rules\Classes\NoNullDebugInfoRule::class,
75
                                Rules\Classes\NoSleepAndWakeupRule::class,
76
                                Rules\Classes\NoThisOutsideObjectRule::class,
77
                                Rules\Classes\NoUnimplementedAbstractMethodsRule::class,
78
                                Rules\Classes\OverrideAttributeRequiredRule::class,
79
                                Rules\Classes\OverridingSignatureRule::class,
80
                                Rules\Classes\PrivateForProtectedRule::class,
81
                                Rules\Classes\PromotedPropertyForAssignmentRule::class,
82
                                Rules\Classes\PublicWithSetVisibilityRule::class,
83
                                Rules\Classes\ReadonlyClassForReadonlyPropertiesRule::class,
84
                                Rules\Classes\ReadonlyForAnnotationRule::class,
85
                                Rules\Classes\ReadonlyForUnwrittenPropertyRule::class,
86
                                Rules\Classes\SelfForCurrentClassRule::class,
87
                                Rules\Classes\SerializeMethodsRequiredRule::class,
88
                                Rules\Classes\StaticForMethodWithoutThisRule::class,
89
                                Rules\Classes\StaticSetStateRequiredRule::class,
90
                                Rules\Classes\StringableRequiredRule::class,
91
                                Rules\Classes\UselessModifierRule::class,
92
                                Rules\Classes\UselessNullInitializationRule::class,
93
                                Rules\Classes\UselessOverridingMethodRule::class,
94
                                Rules\Classes\UselessReturnTypeWillChangeRule::class,
95
                                Rules\Classes\VisibilityRequiredRule::class,
96
                                Rules\Comments\CommentSpacingRule::class,
97
                                Rules\Comments\NoEmptyCommentsRule::class,
98
                                Rules\Comments\NoHashCommentsRule::class,
99
                                Rules\ControlFlow\ArraySearchForFilterRule::class,
100
                                Rules\ControlFlow\ArraySearchForForeachRule::class,
101
                                Rules\ControlFlow\EarlyExitForTrailingIfRule::class,
102
                                Rules\ControlFlow\ElseifNotationRule::class,
103
                                Rules\ControlFlow\FallThroughCommentRule::class,
104
                                Rules\ControlFlow\MatchForSwitchRule::class,
105
                                Rules\ControlFlow\MultilineConditionRule::class,
106
                                Rules\ControlFlow\MultilineForRule::class,
107
                                Rules\ControlFlow\NoAlternativeSyntaxRule::class,
108
                                Rules\ControlFlow\NoBracelessBodiesRule::class,
109
                                Rules\ControlFlow\NoContinueInSwitchRule::class,
110
                                Rules\ControlFlow\NoEmptyStatementsRule::class,
111
                                Rules\ControlFlow\NoRepeatedCatchesRule::class,
112
                                Rules\ControlFlow\NoReturnsInFinallyRule::class,
113
                                Rules\ControlFlow\NoUnreachableCatchesRule::class,
114
                                Rules\ControlFlow\ReturnForBooleanIfRule::class,
115
                                Rules\ControlFlow\SwitchCaseNotationRule::class,
116
                                Rules\ControlFlow\SwitchCaseSpacingRule::class,
117
                                Rules\ControlFlow\TernaryForIfRule::class,
118
                                Rules\ControlFlow\ThrowableForExceptionRule::class,
119
                                Rules\ControlFlow\ThrowExpressionForNullGuardRule::class,
120
                                Rules\ControlFlow\UselessBracesRule::class,
121
                                Rules\ControlFlow\UselessCatchVariableRule::class,
122
                                Rules\ControlFlow\UselessElseRule::class,
123
                                Rules\ControlFlow\UselessReturnRule::class,
124
                                Rules\ControlFlow\UselessVersionCheckRule::class,
125
                                Rules\Expressions\BinaryOperatorSpacingRule::class,
126
                                Rules\Expressions\CastCanonicalTypeRule::class,
127
                                Rules\Expressions\CloneWithNotationRule::class,
128
                                Rules\Expressions\CombinedAssignmentForRepeatedTargetRule::class,
129
                                Rules\Expressions\EmptyArgumentParenthesesRule::class,
130
                                Rules\Expressions\ExplicitPrecedenceRequiredRule::class,
131
                                Rules\Expressions\IncrementRule::class,
132
                                Rules\Expressions\InstantiationWrappingRule::class,
133
                                Rules\Expressions\LogicalOperatorNotationRule::class,
134
                                Rules\Expressions\MemberAccessSpacingRule::class,
135
                                Rules\Expressions\MultilineBinaryOperatorRule::class,
136
                                Rules\Expressions\MultilineChainRule::class,
137
                                Rules\Expressions\MultilineMatchArmRule::class,
138
                                Rules\Expressions\MultilineMatchRule::class,
139
                                Rules\Expressions\MultilineTernaryRule::class,
140
                                Rules\Expressions\NoBacktickOperatorsRule::class,
141
                                Rules\Expressions\NoDoubleNegationsRule::class,
142
                                Rules\Expressions\NoErrorSuppressionRule::class,
143
                                Rules\Expressions\NoLooseComparisonsRule::class,
144
                                Rules\Expressions\NoLooseNumberComparisonsRule::class,
145
                                Rules\Expressions\NotEqualsNotationRule::class,
146
                                Rules\Expressions\NullCoalescingForNullTernaryRule::class,
147
                                Rules\Expressions\NullsafeForGuardedAccessRule::class,
148
                                Rules\Expressions\OperandSpacingRule::class,
149
                                Rules\Expressions\PipeForNestedCallsRule::class,
150
                                Rules\Expressions\ShortTernaryRule::class,
151
                                Rules\Expressions\TernaryOperatorSpacingRule::class,
152
                                Rules\Expressions\UselessParenthesesAfterConstructRule::class,
153
                                Rules\Expressions\UselessTernaryOperatorRule::class,
154
                                Rules\Expressions\YodaRule::class,
155
                                Rules\Files\DeclareSpacingRule::class,
156
                                Rules\Files\FinalLineEndingsRule::class,
157
                                Rules\Files\LineEndingRule::class,
158
                                Rules\Files\LineLengthRule::class,
159
                                Rules\Files\NoBomRule::class,
160
                                Rules\Files\NoClosingTagRule::class,
161
                                Rules\Files\NoInvisibleCharactersRule::class,
162
                                Rules\Files\NoTrailingWhitespaceRule::class,
163
                                Rules\Files\OpeningTagNotationRule::class,
164
                                Rules\Files\StrictTypesRequiredRule::class,
165
                                Rules\Functions\ArrayFirstLastNotationRule::class,
166
                                Rules\Functions\ArrowFunctionForClosureRule::class,
167
                                Rules\Functions\CallableNotationRule::class,
168
                                Rules\Functions\ClampForMinMaxRule::class,
169
                                Rules\Functions\CsvEscapeArgumentRequiredRule::class,
170
                                Rules\Functions\FirstClassCallableForStringRule::class,
171
                                Rules\Functions\FunctionNameSpacingRule::class,
172
                                Rules\Functions\GetDebugTypeForTernaryRule::class,
173
                                Rules\Functions\JsonValidateForDecodeRule::class,
174
                                Rules\Functions\MethodCasingRule::class,
175
                                Rules\Functions\MultilineCallRule::class,
176
                                Rules\Functions\MultilineClosureUseRule::class,
177
                                Rules\Functions\MultilineSignatureRule::class,
178
                                Rules\Functions\NamedArgumentForBooleanRule::class,
179
                                Rules\Functions\NamedArgumentSpacingRule::class,
180
                                Rules\Functions\NewInitializerForNullDefaultRule::class,
181
                                Rules\Functions\NoAliasFunctionsRule::class,
182
                                Rules\Functions\NoCallUserFuncRule::class,
183
                                Rules\Functions\NoConversionFunctionsRule::class,
184
                                Rules\Functions\NoDebugOutputRule::class,
185
                                Rules\Functions\NoDirnameOfFileRule::class,
186
                                Rules\Functions\NoExplicitInvokeCallsRule::class,
187
                                Rules\Functions\NoInnerFunctionsRule::class,
188
                                Rules\Functions\NoIsNullRule::class,
189
                                Rules\Functions\NoManualEmptyArrayTestsRule::class,
190
                                Rules\Functions\NoManualEmptyStringTestsRule::class,
191
                                Rules\Functions\NoManualSubstringTestsRule::class,
192
                                Rules\Functions\NoNullArgumentsRule::class,
193
                                Rules\Functions\NoOutOfRangeChrRule::class,
194
                                Rules\Functions\NoSettypeRule::class,
195
                                Rules\Functions\NoUncountableCountsRule::class,
196
                                Rules\Functions\RedundantArgumentsRule::class,
197
                                Rules\Functions\RoundingModeNotationRule::class,
198
                                Rules\Functions\SensitiveParameterRequiredRule::class,
199
                                Rules\Functions\StaticForClosureWithoutThisRule::class,
200
                                Rules\Functions\StrictComparisonArgumentRequiredRule::class,
201
                                Rules\Functions\UselessParameterDefaultRule::class,
202
                                Rules\Literals\BuiltinCasingRule::class,
203
                                Rules\Literals\HeredocIndentationRule::class,
204
                                Rules\Literals\NoDollarBraceInterpolationsRule::class,
205
                                Rules\Literals\NoImplicitBackslashesRule::class,
206
                                Rules\Literals\NoTrailingWhitespaceInStringRule::class,
207
                                Rules\Literals\NowdocForHeredocRule::class,
208
                                Rules\Literals\NumberNotationRule::class,
209
                                Rules\Literals\OctalNotationRule::class,
210
                                Rules\Literals\StringQuotesRule::class,
211
                                Rules\Literals\UselessStringConcatenationRule::class,
212
                                Rules\Namespaces\DeclaredNameCasingRule::class,
213
                                Rules\Namespaces\ForeignNameQualificationRule::class,
214
                                Rules\Namespaces\GlobalNameQualificationRule::class,
215
                                Rules\Namespaces\ImportNotationRule::class,
216
                                Rules\Namespaces\ImportOrderRule::class,
217
                                Rules\Namespaces\MultilineImportRule::class,
218
                                Rules\Namespaces\NoReservedNamesRule::class,
219
                                Rules\Namespaces\NoUnlistedNamespacedDeclarationsRule::class,
220
                                Rules\Namespaces\NoUnusedImportsRule::class,
221
                                Rules\Namespaces\OptimizedCallNotationRule::class,
222
                                Rules\Namespaces\UselessAliasRule::class,
223
                                Rules\Namespaces\UselessCurrentNamespaceImportRule::class,
224
                                Rules\Namespaces\UselessLeadingBackslashRule::class,
225
                                Rules\PhpDoc\AnnotationCasingRule::class,
226
                                Rules\PhpDoc\AssertForInlineVarRule::class,
227
                                Rules\PhpDoc\DeprecatedAttributeForAnnotationRule::class,
228
                                Rules\PhpDoc\ForbiddenAnnotationsRule::class,
229
                                Rules\PhpDoc\ForbiddenPhpdocLinesRule::class,
230
                                Rules\PhpDoc\NoConsecutivePhpdocsRule::class,
231
                                Rules\PhpDoc\NoInvalidAnnotationsRule::class,
232
                                Rules\PhpDoc\NoPlainPhpdocsRule::class,
233
                                Rules\PhpDoc\PhpdocAboveAttributesRule::class,
234
                                Rules\PhpDoc\PhpdocAlignmentRule::class,
235
                                Rules\PhpDoc\PhpdocBlankLinesRule::class,
236
                                Rules\PhpDoc\PhpdocTypeNotationRule::class,
237
                                Rules\PhpDoc\PromotedPropertyAnnotationPositionRule::class,
238
                                Rules\PhpDoc\PropertyPhpdocLineSpanRule::class,
239
                                Rules\PhpDoc\UselessConstantVarAnnotationRule::class,
240
                                Rules\PhpDoc\UselessInheritdocRule::class,
241
                                Rules\Types\NativeTypeRequiredRule::class,
242
                                Rules\Types\NeverForThrowingFunctionRule::class,
243
                                Rules\Types\NullableTypeForDefaultNullRule::class,
244
                                // after the native types written from the annotations, which they then repeat
245
                                Rules\PhpDoc\UselessTypeAnnotationsRule::class,
246
                                Rules\Types\ConstantTypeRequiredRule::class,
247
                                Rules\Types\TypeDeclarationSpacingRule::class,
248
                                Rules\Types\TypeNotationRule::class,
249
                                // what a map replaces is written first, so that what it forbids is reported of what remains
250
                                Rules\Upgrading\ReplacedClassesRule::class,
251
                                Rules\Upgrading\ReplacedFunctionsRule::class,
252
                                Rules\Upgrading\ReplacedMembersRule::class,
253
                                Rules\Upgrading\ReplacedCallsRule::class,
254
                                Rules\Upgrading\ReplacedFunctionCallsRule::class,
255
                                Rules\Upgrading\ForbiddenSymbolsRule::class,
256
                                Rules\Upgrading\ForbiddenMembersRule::class,
257
                                Rules\Upgrading\AttributeForAnnotationRule::class,
258
                                Rules\Upgrading\AttributeForMemberRule::class,
259
                                Rules\Upgrading\NoDeprecatedClassesRule::class,
260
                                Rules\Upgrading\NoDeprecatedMembersRule::class,
261
                                Rules\Upgrading\NoDeprecatedFunctionsRule::class,
262
                                Rules\Upgrading\NoDeprecatedPhpArgumentsRule::class,
263
                                // what the rewrites leave of a string naming a class, and what none of them could see
264
                                Rules\Upgrading\UnseenReferencesRule::class,
265
                                Rules\Variables\NoGlobalStatementsRule::class,
266
                                Rules\Variables\NoRepeatedAssignmentsRule::class,
267
                                Rules\Variables\NoSeparateIssetsRule::class,
268
                                Rules\Variables\NoSeparateUnsetsRule::class,
269
                                Rules\Whitespace\AttributePositionRule::class,
270
                                Rules\Whitespace\AttributeSpacingRule::class,
271
                                Rules\Whitespace\BlockBlankLinesRule::class,
272
                                Rules\Whitespace\BracesPositionRule::class,
273
                                Rules\Whitespace\CommaSpacingRule::class,
274
                                Rules\Whitespace\ConstructSpacingRule::class,
275
                                Rules\Whitespace\DelimiterSpacingRule::class,
276
                                Rules\Whitespace\IndentationRule::class,
277
                                Rules\Whitespace\MemberBlankLinesRule::class,
278
                                Rules\Whitespace\MultilineAttributeRule::class,
279
                                Rules\Whitespace\NoStatementsSharingLineRule::class,
280
                                Rules\Whitespace\SemicolonSpacingRule::class,
281
                                Rules\Whitespace\SingleLevelIndentationRule::class,
282
                                Rules\Whitespace\StatementBlankLinesRule::class,
283
                        ],
284
                        // the decisions no single rule owns, each turning on the rules that name it in `RuleInfo::$decisions`
285
                        decisions: [
286
                                // the style of the run, which the engine reads and every rule writing code takes
287
                                new Decision('file.lineEnding', new Words([
1 ✔
288
                                        'LF' => 'every line ends with LF',
289
                                        'CRLF' => 'every line ends with CRLF',
290
                                        'majority' => 'every line ends as most lines of the file do, LF on a tie',
291
                                ]), 'The line ending of every line, which the code written new takes too; under `keep` that follows the file'),
1 ✔
292
                                new Decision(
1 ✔
293
                                        'file.lineLength',
1 ✔
294
                                        new Count(1, range: false, words: ['none' => 'no line is too wide']),
1 ✔
295
                                        'The widest line, by which what spreads over lines is split',
1 ✔
296
                                        kind: DecisionKind::Parameter,
1 ✔
297
                                        default: 'none',
1 ✔
298
                                ),
299
                                new Decision('file.lineLengthExcept', new Names([
1 ✔
300
                                        'imports' => 'a `use` import other than a group use on one line, which cannot be split',
301
                                        'strings' => 'a line that would fit were each of its string literals an empty pair of quotes, a string being never split',
302
                                        'argument' => 'the arguments of a call, of `new` and of an attribute, the variables of `unset()` and `isset()`',
303
                                        'parameter' => 'the parameters of a function or a method',
304
                                        'closureUse' => 'the variables of the `use` of a closure',
305
                                        'attribute' => 'the attributes of one group',
306
                                        'condition' => 'a condition of `if`, `elseif`, `while` and `do-while`',
307
                                        'chain' => 'a chain of method calls',
308
                                        'ternary' => 'a ternary',
309
                                        'for' => 'the header of a `for`',
310
                                        'logical' => 'the operands of a boolean operator outside a condition',
311
                                        'concatenation' => 'the operands of `.`',
312
                                        'arithmetic' => 'the operands of `+`, `-`, `*`, `/`, `%` and `**`',
313
                                        'bitwise' => 'the operands of `|`, `&`, `^`, `<<` and `>>`',
314
                                        'coalesce' => 'the operands of `??`',
315
                                        'pipe' => 'the operands of `|>`',
316
                                        'array' => 'the items of an array, which `multiline.maxWidth.array` spreads all the same',
317
                                        'list' => 'the items of `list()`',
318
                                        'implements' => 'the interfaces a class implements or an interface extends',
319
                                        'matchCondition' => 'the conditions of a `match` arm',
320
                                ], regularExpressions: true), 'What a line too wide leaves as it is: a construct named is not spread over lines for its width, and a line it stands on, one a regular expression matches, or with `strings` one wide only for its string literals, is not reported', kind: DecisionKind::Parameter, default: ['imports']),
1 ✔
321
                                new Decision('indentation.unit', new Words([
1 ✔
322
                                        'tab' => 'one tab per level',
323
                                        '4 spaces' => 'four spaces per level',
324
                                        '2 spaces' => 'two spaces per level',
325
                                ]), 'Every line indented by the construct it continues, one level per nesting, the level being this unit; under `keep` a line stays where it is'),
1 ✔
326
                                new Decision(
1 ✔
327
                                        'indentation.tabWidth',
1 ✔
328
                                        new Count(1, 8, range: false),
1 ✔
329
                                        'How many columns a tab counts for in the width of a line',
1 ✔
330
                                        kind: DecisionKind::Parameter,
1 ✔
331
                                        default: 4,
1 ✔
332
                                ),
333
                                ...self::createIndentationDecisions(),
1 ✔
334
                                ...self::createImportDecisions(),
1 ✔
335
                                new Decision(
1 ✔
336
                                        'spacing.keyword',
1 ✔
337
                                        new Shapes(['spaced' => ['return $x', 'a single space']]),
1 ✔
338
                                        'The space after a keyword followed by code on its line, `return`, `new`, `if`, `function`, a modifier and the words of the head of a class among them, and around a keyword continuing a statement, `else`, `catch`, `finally`, the `while` of a `do`, `as`, `insteadof` and the `use` of a closure, which stay on the line of what is before them',
1 ✔
339
                                ),
340
                                new Decision(
1 ✔
341
                                        'multiline.operatorPosition.ternary',
1 ✔
342
                                        Domain::operatorPosition(),
1 ✔
343
                                        'Where `?`, `:` and `?:` of a ternary stand at a line break, of a ternary spread over lines too',
1 ✔
344
                                ),
345
                                // where a comparison stands, which the rule of the conditions splits a condition that is one at
346
                                new Decision(
1 ✔
347
                                        'multiline.operatorPosition.comparison',
1 ✔
348
                                        Domain::operatorPosition(),
1 ✔
349
                                        'Where a comparison stands at a line break: one ending its line moves only where the line joined after it would be too wide, one opening its line joins the line before it, what follows staying on its line unless it would be too wide',
1 ✔
350
                                ),
351

352
                                // how far a function PHP optimizes is written out, which decides the arguments of its call too
353
                                Rules\Namespaces\QualificationPolicy::createOptimizedDecision(
1 ✔
354
                                        'qualification.function.optimized',
1 ✔
355
                                        'A global function whose call PHP compiles to one opcode once it knows the function is global, `count()`, `strlen()`, `is_int()` and the others; a call of it written imported or with the backslash has its arguments passed positionally and an unpacked one reported',
1 ✔
356
                                        '`strlen()`',
1 ✔
357
                                        '`use function strlen;`',
1 ✔
358
                                        '`\strlen()`',
1 ✔
359
                                        'optimizes it',
1 ✔
360
                                        'A function is optimized in a namespace where one of its calls there is, an unpacked or named argument aside, `in_array()` only with a constant array, and every reference to it in that namespace is then written so; one none of whose calls is optimized is decided by `function.global`.',
1 ✔
361
                                ),
362

363
                                // the lines below a doc comment, of a member as of a declaration among statements
364
                                new Decision(
1 ✔
365
                                        'blankLines.afterPhpdoc',
1 ✔
366
                                        Domain::blankLines(),
1 ✔
367
                                        'Between a doc comment and the declaration it belongs to, or the first attribute of the declaration',
1 ✔
368
                                ),
369

370
                                // the classes a native type takes as iterable
371
                                new Decision(
1 ✔
372
                                        'types.traversableClasses',
1 ✔
373
                                        new Names,
1 ✔
374
                                        'Classes treated like `array` and `iterable`, whose annotation says what their items are',
1 ✔
375
                                        kind: DecisionKind::Parameter,
1 ✔
376
                                        default: ['Traversable'],
377
                                ),
378

379
                                // the maps of what the libraries retired, those the project writes and those the upgrading files of the installed
380
                                // packages lay under them, each read by its grammar
381
                                new Decision(
1 ✔
382
                                        'upgrading.packages',
1 ✔
383
                                        new Flag,
1 ✔
384
                                        'Whether the code follows the upgrading files of the installed packages, their maps laid under those the project writes and the rules of the plugin of a package turned on where its files say',
1 ✔
385
                                        kind: DecisionKind::Parameter,
1 ✔
386
                                        default: false,
387
                                ),
388
                                new Decision(
1 ✔
389
                                        PackageDiscovery::PhpDecision,
1 ✔
390
                                        Domain::state('forbidden'),
1 ✔
391
                                        'A function, a constant or a member PHP deprecated, written as what replaces it as the upgrading data of PHP say, `mb_convert_encoding()` for `utf8_encode()`, or reported',
1 ✔
392
                                ),
393
                                new Decision(
1 ✔
394
                                        MemberMapGrammar::ReplacedClasses,
1 ✔
395
                                        new Map(new GrammarEntry, wildcards: false, grammar: self::createReplacedClassesGrammar(), caseInsensitive: true),
1 ✔
396
                                        'A class written instead of another one, both fully qualified (`Acme\\Old\\Mailer: Acme\\Mail\\Mailer`)',
1 ✔
397
                                ),
398
                                new Decision(
1 ✔
399
                                        MemberMapGrammar::ReplacedFunctions,
1 ✔
400
                                        new Map(new GrammarEntry, wildcards: false, grammar: self::createReplacedFunctionsGrammar(), caseInsensitive: true),
1 ✔
401
                                        'A function written instead of another one (`acme_send: Acme\\Mail\\send`)',
1 ✔
402
                                ),
403
                                new Decision(
1 ✔
404
                                        MemberMapGrammar::ReplacedMembers,
1 ✔
405
                                        new Map(
1 ✔
406
                                                new GrammarEntry,
1 ✔
407
                                                wildcards: false,
408
                                                grammar: self::createReplacedMembersGrammar(),
1 ✔
409
                                                canonicalize: MemberPattern::canonicalizeKey(...),
1 ✔
410
                                        ),
411
                                        'A constant, a method or a property written instead of another one of the class (`Acme\\Mail\\Mailer::send(): sendMessage()`)',
1 ✔
412
                                ),
413
                                new Decision(
1 ✔
414
                                        MemberMapGrammar::ReplacedCalls,
1 ✔
415
                                        new Map(
1 ✔
416
                                                new GrammarEntry,
1 ✔
417
                                                wildcards: false,
418
                                                grammar: self::createReplacedCallsGrammar(),
1 ✔
419
                                                canonicalize: MemberPattern::canonicalizeKey(...),
1 ✔
420
                                        ),
421
                                        'A call written as the template says (`Acme\\Mail\\Mailer::send($to, $body): send(new Message($to, $body))`)',
1 ✔
422
                                ),
423
                                new Decision(
1 ✔
424
                                        MemberMapGrammar::ForbiddenClasses,
1 ✔
425
                                        new Map(new GrammarEntry, wildcards: false, grammar: self::createForbiddenClassesGrammar(), caseInsensitive: true),
1 ✔
426
                                        'A class that may not be used, with what to do instead (`Acme\\Legacy\\Db: "use the repository"`)',
1 ✔
427
                                ),
428
                                new Decision(
1 ✔
429
                                        MemberMapGrammar::ForbiddenFunctions,
1 ✔
430
                                        new Map(new GrammarEntry, grammar: self::createForbiddenFunctionsGrammar(), caseInsensitive: true),
1 ✔
431
                                        'A function that may not be called, with what to do instead',
1 ✔
432
                                ),
433
                                new Decision(
1 ✔
434
                                        MemberMapGrammar::ForbiddenConstants,
1 ✔
435
                                        new Map(new GrammarEntry, grammar: self::createForbiddenConstantsGrammar()),
1 ✔
436
                                        'A global constant that may not be used, with what to do instead (`E_STRICT: "it no longer does anything"`)',
1 ✔
437
                                ),
438
                                new Decision(
1 ✔
439
                                        MemberMapGrammar::ForbiddenMembers,
1 ✔
440
                                        new Map(
1 ✔
441
                                                new GrammarEntry,
1 ✔
442
                                                wildcards: false,
443
                                                grammar: self::createForbiddenMembersGrammar(),
1 ✔
444
                                                canonicalize: MemberPattern::canonicalizeKey(...),
1 ✔
445
                                        ),
446
                                        'A constant, a method or a property that may not be used, with what to do instead',
1 ✔
447
                                ),
448
                                new Decision(
1 ✔
449
                                        MemberMapGrammar::AttributeForAnnotation,
1 ✔
450
                                        new Map(new GrammarEntry, grammar: self::createAttributeForAnnotationGrammar()),
1 ✔
451
                                        'An attribute written for an annotation (`@ORM\\Entity: ORM\\Entity`)',
1 ✔
452
                                ),
453
                                new Decision(
1 ✔
454
                                        MemberMapGrammar::AttributeForMember,
1 ✔
455
                                        new Map(
1 ✔
456
                                                new GrammarEntry,
1 ✔
457
                                                wildcards: false,
458
                                                grammar: self::createAttributeForMemberGrammar(),
1 ✔
459
                                                canonicalize: MemberPattern::canonicalizeKey(...),
1 ✔
460
                                        ),
461
                                        'An attribute written for a member the class declares by convention',
1 ✔
462
                                ),
463

464
                                // the newer constructs, decided once for every rule writing them
465
                                new Decision(
1 ✔
466
                                        'upgrading.functions.arraySearchFunctions',
1 ✔
467
                                        Domain::state('required'),
1 ✔
468
                                        '`array_any()`, `array_all()`, `array_find()` and `array_find_key()` for a `foreach` or an `array_filter()` that only asks what they answer',
1 ✔
469
                                ),
470
                                new Decision(
1 ✔
471
                                        'upgrading.syntax.firstClassCallables',
1 ✔
472
                                        Domain::state('required'),
1 ✔
473
                                        '`foo(...)` for `Closure::fromCallable()`, a forwarding closure and `\'self::foo\'`; from PHP 8.6 a partial application',
1 ✔
474
                                ),
475
                        ],
476
                );
477
        }
478

479

480
        /** @return list<Decision>  the levels of the lines continuing a construct, which a rule deciding by the width of a line waits for */
481
        private static function createIndentationDecisions(): array
482
        {
483
                $level = new Count(0, 1, range: false);
1 ✔
484
                return [
485
                        new Decision(
1 ✔
486
                                IndentationPlan::Binary,
1 ✔
487
                                $level,
488
                                'The levels a line opened by `&&`, `+`, `.` steps in by from the start of its expression, 1 at least where the expression shares its first line',
1 ✔
489
                        ),
490
                        new Decision(IndentationPlan::Ternary, $level, 'The levels `?` and `:` opening a line step in by'),
1 ✔
491
                        new Decision(IndentationPlan::SwitchCase, $level, 'The levels `case` steps in by from `switch`'),
1 ✔
492
                        new Decision(IndentationPlan::Chain, new Words([
1 ✔
493
                                'flat' => 'every link one level below the start',
494
                                'nested' => 'a link one level deeper or shallower than the link before it',
495
                        ]), 'Where the links of a chain spread over lines stand'),
1 ✔
496
                ];
497
        }
498

499

500
        /** @return list<Decision>  how the names of the imports are put into statements, which an import a rule adds takes too */
501
        private static function createImportDecisions(): array
502
        {
503
                $shapes = new Words([
1 ✔
504
                        'separated' => 'a `use` of its own for every name, `use Foo; use Bar;`',
1 ✔
505
                        'combined' => 'all names of the kind in one `use`, `use Foo, Bar;`, one per namespace declaration',
506
                        'grouped' => 'the names of one namespace in one group use, `use Acme\Shop\{Order, Cart};`, from `imports.groupMinNames` of them on',
507
                ], tolerance: true);
1 ✔
508
                return [
509
                        new Decision(
1 ✔
510
                                'imports.grouping.class',
1 ✔
511
                                $shapes,
512
                                'How the imports of classes are put into `use` statements, a name of the global namespace never grouped',
1 ✔
513
                        ),
514
                        new Decision(
1 ✔
515
                                'imports.grouping.function',
1 ✔
516
                                $shapes,
517
                                'How the imports of functions are put into `use` statements, a name of the global namespace never grouped',
1 ✔
518
                        ),
519
                        new Decision(
1 ✔
520
                                'imports.grouping.constant',
1 ✔
521
                                $shapes,
522
                                'How the imports of constants are put into `use` statements, a name of the global namespace never grouped',
1 ✔
523
                        ),
524
                ];
525
        }
526

527

528
        private static function createReplacedClassesGrammar(): Schema
529
        {
530
                $name = fn() => Expect::string()->pattern(self::QualifiedName);
1 ✔
531
                return Expect::arrayOf($name(), $name())
1 ✔
532
                        ->description('The class → the class written instead, both fully qualified')
1 ✔
533
                        ->transform(function (array $options, Context $context): array {
1 ✔
534
                                foreach ($options as $old => $new) {
1 ✔
535
                                        if (strcasecmp(ltrim((string) $old, '\\'), ltrim($new, '\\')) === 0) {
1 ✔
UNCOV
536
                                                $context->addError("The class `$old` is given as its own replacement.", 'dresscode.sameClass');
×
537
                                        }
538
                                }
539

540
                                return $options;
1 ✔
541
                        });
1 ✔
542
        }
543

544

545
        private static function createReplacedFunctionsGrammar(): Schema
546
        {
547
                return Expect::arrayOf(
1 ✔
548
                        Expect::string()->pattern(self::QualifiedName . '(::\w+)?'),
1 ✔
549
                        Expect::string()->pattern(self::QualifiedName),
1 ✔
550
                )
551
                        ->description('The function, global or of a namespace → the function or the static method written instead')
1 ✔
552
                        ->transform(function (array $options, Context $context): array {
1 ✔
553
                                foreach ($options as $old => $new) {
1 ✔
554
                                        if (strcasecmp(ltrim((string) $old, '\\'), ltrim($new, '\\')) === 0) {
1 ✔
UNCOV
555
                                                $context->addError("The function `$old()` is given as its own replacement.", 'dresscode.sameFunction');
×
556
                                        }
557
                                }
558

559
                                return $options;
1 ✔
560
                        });
1 ✔
561
        }
562

563

564
        private static function createReplacedMembersGrammar(): Schema
565
        {
566
                return MemberMapGrammar::createMapSchema(
1 ✔
567
                        MemberMapGrammar::createCodeSchema(),
1 ✔
568
                        'The replaced member, `Class::name` (a constant or a method), `Class::name()` (a method) or `Class::$name` (a property) → the member written instead: its name alone in the same class, `Other::name` in another one, or `\function` for the global function a method becomes',
1 ✔
569
                        MemberTarget::fromCode(...),
1 ✔
570
                );
571
        }
572

573

574
        private static function createReplacedCallsGrammar(): Schema
575
        {
576
                $write = Expect::anyOf(MemberMapGrammar::Removed, MemberMapGrammar::createCodeSchema());
1 ✔
577
                return MemberMapGrammar::createMapSchema(
1 ✔
578
                        Expect::anyOf(
1 ✔
579
                                $write,
1 ✔
580
                                Expect::structure(['write' => (clone $write)->required(), 'because' => Expect::string()])->castTo('array'),
1 ✔
581
                        ),
582
                        'The replaced use, `Class::name($a, true)`, `Class::name(...$args)` with any arguments, `Class::name()` without any, `Class::__construct($a)`, `Class::$name::get`, `Class::$name::set`, a magic method for the syntax PHP calls it by, or a call of a function, `name($a)` → the expression written instead, with the placeholders of the key, `$value` what is assigned, or `removed` for a call of a function or a method that does nothing; `{write: …, because: …}` where the rewrite may change what the code does',
1 ✔
583
                        CallTemplate::fromEntry(...),
1 ✔
584
                        CallTemplate::fromEntry(...),
1 ✔
585
                )->transform(CallTemplate::checkCycles(...));
1 ✔
586
        }
587

588

589
        private static function createForbiddenClassesGrammar(): Schema
590
        {
591
                return Expect::arrayOf(Expect::string()->nullable(), Expect::string()->pattern(self::QualifiedName))
1 ✔
592
                        ->description('The forbidden class, fully qualified → what to do instead, as the end of the message, or null for none');
1 ✔
593
        }
594

595

596
        private static function createForbiddenFunctionsGrammar(): Schema
597
        {
598
                return Expect::arrayOf(Expect::string()->nullable())
1 ✔
599
                        ->description('The forbidden function or a pattern with `*`, a name without a backslash meaning the global function → what to do instead, as the end of the message, or null for none');
1 ✔
600
        }
601

602

603
        private static function createForbiddenConstantsGrammar(): Schema
604
        {
605
                return Expect::arrayOf(Expect::string()->nullable())
1 ✔
606
                        ->description('The forbidden constant or a pattern with `*`, in its letter case, a name without a backslash meaning the global constant → what to do instead, as the end of the message, or null for none');
1 ✔
607
        }
608

609

610
        private static function createForbiddenMembersGrammar(): Schema
611
        {
612
                return MemberMapGrammar::createMapSchema(
1 ✔
613
                        Expect::string()->nullable(),
1 ✔
614
                        'The forbidden member, `Class::name` (a constant or a method), `Class::name(...$args)` (a method), `Class::$name` (a property), `Class::$name::get` or `::set` (a read or a write of it), `Class::__construct(...$args)`, or a call with the shape of its arguments, `Class::name()` being one without any → what to do instead, as the end of the message, or null for none',
1 ✔
615
                );
616
        }
617

618

619
        private static function createAttributeForAnnotationGrammar(): Schema
620
        {
621
                return Expect::arrayOf(
1 ✔
622
                        MemberMapGrammar::createCodeSchema(),
1 ✔
623
                        Expect::string()->pattern('@?[\w-]+|\\\\?\w+(?:\\\\\w+)+|\\\\\w+|\\\\?\w+(?:\\\\\w+)*\\\\\*'),
1 ✔
624
                )
625
                        ->description('The annotation, without the `@`, the class of an attribute, fully qualified, or a namespace of annotations, `Acme\Validation\*` → the attribute written instead, its class fully qualified, with its arguments where it has any, or the namespace of the attributes, `Acme\Validation\*`')
1 ✔
626
                        ->transform(function (array $options, Context $context): array {
1 ✔
627
                                foreach ($options as $key => $code) {
1 ✔
628
                                        if (str_ends_with((string) $key, '*')) {
1 ✔
629
                                                if ($code !== MemberMapGrammar::Keep && AttributeTarget::findNamespace($code) === null) {
1 ✔
630
                                                        $context->addError(
1 ✔
631
                                                                "The namespace `$key` is written instead as "
1 ✔
632
                                                                . Violation::formatCode($code)
1 ✔
633
                                                                . ', which is not a namespace ending with `\\*`.',
1 ✔
634
                                                                'dresscode.attributeCode',
1 ✔
635
                                                        );
636
                                                }
637
                                        } elseif ($code !== MemberMapGrammar::Keep && AttributeTarget::fromCode($code) === null) {
1 ✔
638
                                                $old = str_contains((string) $key, '\\')
1 ✔
639
                                                        ? '#[' . ltrim((string) $key, '\\') . ']'
1 ✔
640
                                                        : '@' . ltrim((string) $key, '@');
1 ✔
641
                                                $context->addError(
1 ✔
642
                                                        'The attribute '
643
                                                        . Violation::formatCode($code)
1 ✔
644
                                                        . " written instead of `$old` is not a class with its arguments, `Class` or `Class(arguments)`.",
1 ✔
645
                                                        'dresscode.attributeCode',
1 ✔
646
                                                );
647
                                        }
648
                                }
649

650
                                return $options;
1 ✔
651
                        });
1 ✔
652
        }
653

654

655
        private static function createAttributeForMemberGrammar(): Schema
656
        {
657
                return Expect::arrayOf(Expect::string(), Expect::string())
1 ✔
658
                        ->description('The member of an ancestor, `Class::$name`, `Class::method()` or `\'Class::$name = literal\'` for that value only, or an interface the class implements → the attribute written instead, `$value` standing for the value of the property or what the method returns')
1 ✔
659
                        ->transform(function (array $options, Context $context): array {
1 ✔
660
                                foreach ($options as $key => $value) {
1 ✔
661
                                        try {
662
                                                if ($value !== MemberMapGrammar::Keep) {
1 ✔
663
                                                        AttributeForMemberEntry::fromEntry((string) $key, $value);
1 ✔
664
                                                }
UNCOV
665
                                        } catch (\InvalidArgumentException $e) {
×
UNCOV
666
                                                $context->addError($e->getMessage(), 'dresscode.memberMap');
×
667
                                        }
668
                                }
669

670
                                return $options;
1 ✔
671
                        });
1 ✔
672
        }
673
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc