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

dg / dresscode / 42040857956

05 Nov 2026 12:36PM UTC coverage: 97.783% (+0.7%) from 97.051%
42040857956

push

github

dg
PhpStan: the types take the extensions of the project

The extensions were those phpstan/extension-installer registered in the installation DressCode runs from, so the types
depended on how DressCode was installed. A global one saw none, and reported a null from preg_replace() that the PHPStan
of a project with nette/phpstan-rules does not see, where the fix it offers fails that PHPStan; one made by
composer create-project brought its own nette/phpstan-rules into every project.

Now they are what the installer of the project includes, read from its installed.json, and only the classes of the
extensions are loaded from its vendor, the process keeping the packages of its own installation. This also lets an
extension that phpstan.neon includes by a path into vendor start.

1a3eaac4-d0da-4312-8c24-b7fb27c7b977

34 of 34 new or added lines in 3 files covered. (100.0%)

188 existing lines in 44 files now uncovered.

23290 of 23818 relevant lines covered (97.78%)

0.98 hits per line

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

98.78
/src/Config/ConfigResolver.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\{Config, ConfigurationException, Decision, DecisionKind, Plugin, Profile, Rule, RuleInfo, Value, Values};
11
use DressCode\Domains\Map;
12
use PhpSyntax\SymbolKind;
13
use function count, is_array, is_string;
14

15

16
/**
17
 * Lays the profiles that decide for a file one over another, each above the presets it uses, what the installed
18
 * packages say under them all, and resolves every decision and the rule owning it once into a ResolvedConfig.
19
 * @internal
20
 */
21
final class ConfigResolver
22
{
23
        /** the decision that lays the maps of the upgrading data of the packages under those of the project */
24
        private const PackagesDecision = 'upgrading.packages';
25

26
        /** @var array<string, string> */
27
        private array $warnings = [];
28

29
        /** @var array<string, Profile>  the presets by the path of their file */
30
        private array $presetFiles = [];
31

32
        /** @var list<string>  the preset files being laid, each used by the one before it */
33
        private array $using = [];
34

35
        /** @var \WeakMap<Config, array<class-string<Rule>, true>>  the rules some override of a resolved configuration turns on */
36
        private \WeakMap $rulesOfOverrides;
37

38

39
        public function __construct(
40
                private readonly PluginRegistry $registry,
1 ✔
41
                /**
42
                 * @var list<UpgradingData>  what the installed packages say, the maps of each laid under the project where it says
43
                 * `upgrading.packages: yes`
44
                 */
45
                private readonly array $upgradingData = [],
1 ✔
46
                /** the packages the project stands on, which decide whether a rule requiring one runs */
47
                private readonly ProjectPackages $project = new ProjectPackages,
1 ✔
48
                /** the run can get the types the configuration or the command line asks for; without them it resolves as if it asked for none */
49
                private readonly bool $typesAvailable = true,
1 ✔
50
                /** the directory a file in `use` of the configuration and its overrides is relative to */
51
                private readonly string $root = '.',
1 ✔
52
                /** @var list<string>  the packages whose plugins the project does not let in, so the maps of their rules are unknown */
53
                private readonly array $pluginsSkipped = [],
1 ✔
54
        ) {
55
                $this->rulesOfOverrides = new \WeakMap;
1 ✔
56
        }
1 ✔
57

58

59
        /**
60
         * What the caller should tell the user about the configuration, each thing once.
61
         * @return list<string>
62
         */
63
        public function getWarnings(): array
64
        {
65
                return array_values($this->warnings);
1 ✔
66
        }
67

68

69
        /**
70
         * The configuration as data for a file the given overrides match: what every decision ends up with and where it came
71
         * from, the rules owning those that take effect, and why a rule that does not run does not.
72
         * @param  string  $phpTarget  the versions the code is written for as a Composer constraint, unless a profile says another
73
         * @param  list<int>  $overrides  indexes of the overrides that match the file
74
         * @param  ?Profile  $commandLine  laid over everything else
75
         * @param  ?list<string>  $only  decisions, sections, presets and classes of rules the run is narrowed to
76
         * @throws ConfigurationException
77
         */
78
        public function resolve(
79
                Config $config,
80
                string $phpTarget,
81
                array $overrides = [],
82
                ?Profile $commandLine = null,
83
                ?array $only = null,
84
        ): ResolvedConfig
85
        {
86
                $fixRisky = $fixRiskyPaths = $reportOnly = $severities = $use = $suppressionComments = $suppressionExamples = [];
1 ✔
87
                $symbols = [SymbolKind::Function->name => [], SymbolKind::Constant->name => []];
1 ✔
88
                $php = $resolution = null;
1 ✔
89
                $typeAnalysis = ($commandLine instanceof Config ? $commandLine->typeAnalysis : null) ?? $config->typeAnalysis;
1 ✔
90
                $decisionLayers = [];
1 ✔
91
                // what the packages declare lies under every layer, which may add to it
92
                foreach ($this->upgradingData as $package) {
1 ✔
93
                        self::addSymbols($symbols, $package->namespaces, $package->layer->describe());
1 ✔
94
                }
95

96
                ['layers' => $collected, 'repeated' => $repeated] = $this->collectLayers(self::listProfiles($config, $overrides, $commandLine));
1 ✔
97
                foreach ($collected as [$layer, $profile]) {
1 ✔
98
                        try {
99
                                if ($layer->kind === LayerKind::Preset) {
1 ✔
100
                                        $use[] = (string) $layer->name;
1 ✔
101
                                }
102

103
                                $php = $profile->targets['php'] ?? $php;
1 ✔
104
                                $resolution = $profile->nameResolution ?? $resolution;
1 ✔
105

106
                                self::addSymbols($symbols, $profile->namespaces, $layer->describe());
1 ✔
107

108
                                if ($profile->decisions !== []) {
1 ✔
109
                                        new DecisionResolver($this->getCatalogue())->checkLayer($profile->decisions);
1 ✔
110
                                        $decisionLayers[] = [$layer, $profile->decisions];
1 ✔
111
                                }
112

113
                                foreach ($profile->fixRisky as $name) {
1 ✔
114
                                        $expanded = $this->expandName($name);
1 ✔
115
                                        $fixRisky += array_fill_keys($expanded->rules, true);
1 ✔
116
                                        $fixRiskyPaths += array_fill_keys($expanded->paths, true);
1 ✔
117
                                }
118

119
                                foreach ($profile->reportOnly as $name) {
1 ✔
120
                                        $reportOnly += array_fill_keys($this->expandName($name)->paths, true);
1 ✔
121
                                }
122

123
                                $severities[] = $this->collectSeverity($profile->severity);
1 ✔
124

125
                                foreach ($profile->suppressionComments as $pattern => $entry) {
1 ✔
126
                                        // a pattern a later layer says again is that layer's, the example with it
127
                                        $suppressionComments[$pattern] = array_values(array_unique(array_merge(
1 ✔
128
                                                ...array_map($this->resolveSuppressedName(...), $entry['decisions']),
1 ✔
129
                                        )));
130
                                        $suppressionExamples[$pattern] = $entry['example'];
1 ✔
131
                                }
132

133
                        } catch (ConfigurationException $e) {
1 ✔
134
                                throw self::locate($e, $layer);
1 ✔
135
                        }
136
                }
137

138
                $narrowed = $only ? $this->resolveOnly($only) : null;
1 ✔
139
                // an override is resolved for a file it matches, so a name or an option it gets wrong would pass unnoticed until
140
                // such a file comes; each of them is resolved together with the configuration
141
                $resolvedOverrides = $overrides === []
1 ✔
142
                        ? array_map(
1 ✔
143
                                fn(int $index) => $this->resolve($config, $phpTarget, [$index], $commandLine, $only),
1 ✔
144
                                array_keys($config->overrides),
1 ✔
145
                        )
146
                        : [];
1 ✔
147
                // the rules some override turns on, whichever file it applies to, kept for the overrides resolved later; those
148
                // resolved above go without, only what runs being read of them
149
                if ($overrides === []) {
1 ✔
150
                        $ofOverrides = [];
1 ✔
151
                        foreach ($resolvedOverrides as $resolvedOverride) {
1 ✔
152
                                foreach ($resolvedOverride->getActiveRules() as $rule) {
1 ✔
153
                                        $ofOverrides[$rule->class] = true;
1 ✔
154
                                }
155
                        }
156

157
                        $this->rulesOfOverrides[$config] = $ofOverrides;
1 ✔
158
                }
159

160
                $ofOverrides = $this->rulesOfOverrides[$config] ?? [];
1 ✔
161

162
                [$phpTarget, $phpVersion] = $this->resolvePhpTarget($php ?? $phpTarget);
1 ✔
163
                $resolver = new DecisionResolver(
1 ✔
164
                        $this->getCatalogue(),
1 ✔
165
                        $phpTarget,
166
                        $this->project,
1 ✔
167
                        typesAnalyzed: $typeAnalysis !== null && $this->typesAvailable,
1 ✔
168
                        certainNames: $resolution === 'certain',
1 ✔
169
                );
170
                $decisions = $resolver->resolve($decisionLayers);
1 ✔
171
                if ($packageLayers = $this->collectPackageMaps($decisions, $narrowed)) {
1 ✔
172
                        $decisions = $resolver->resolve([...$packageLayers, ...$decisionLayers]);
1 ✔
173
                }
174

175
                $values = $resolver->createValues($decisions, $narrowed === null ? null : $this->collectSelection($narrowed));
1 ✔
176
                foreach ($this->getCatalogue()->getDecisions() as $path => $decision) {
1 ✔
177
                        // a map the run is narrowed away from is refused where its entries are wrong all the same, no rule reading it
178
                        if (
179
                                $decision->domain instanceof Map
1 ✔
180
                                && $decision->domain->grammar !== null
1 ✔
181
                                && !$values->isKept($path)
1 ✔
182
                                && !$values->isSelected($path)
1 ✔
183
                        ) {
184
                                $values->readMap($path);
1 ✔
185
                        }
186
                }
187

188
                $factories = $config->getRuleFactories() + $this->registry->ruleFactories;
1 ✔
189
                $byRule = $active = $inactive = [];
1 ✔
190
                foreach ($decisions as $path => $decision) {
1 ✔
191
                        foreach ($decision->rules as $class) {
1 ✔
192
                                $byRule[$class][$path] = $decision;
1 ✔
193
                        }
194
                }
195

196
                foreach ($this->getCatalogue()->getRuleOrder() as $class) {
1 ✔
197
                        $resolved = $this->resolveRule(
1 ✔
198
                                $class,
199
                                $byRule[$class] ?? [],
1 ✔
200
                                $resolver->findRuleReason($class),
1 ✔
201
                                $values,
202
                                $phpTarget,
203
                                $factories[$class] ?? null,
1 ✔
204
                                isset($fixRisky[$class]),
1 ✔
205
                                isset($ofOverrides[$class]),
1 ✔
206
                        );
207
                        $resolved->isActive() ? $active[$class] = $resolved : $inactive[$class] = $resolved;
1 ✔
208
                }
209

210
                $this->warnRepeated($repeated);
1 ✔
211
                if ($overrides === []) {
1 ✔
212
                        $narrowed === null
1 ✔
213
                                ? $this->checkFixPolicies($config, $active, $ofOverrides)
1 ✔
214
                                : $this->checkOnly($narrowed, $active, $inactive, $ofOverrides, $use);
1 ✔
215
                }
216

217
                // one entry per symbol, spelled the way the first layer naming it spells it
218
                $bySource = fn(array $entries): array => array_column($entries, 1, 0);
1 ✔
219
                return new ResolvedConfig(
1 ✔
220
                        [...array_values($active), ...array_values($inactive)],
1 ✔
221
                        self::resolveIndent($values->get('indentation.unit')),
1 ✔
222
                        self::resolveLineEnding($values->get('file.lineEnding')),
1 ✔
223
                        $phpVersion,
224
                        $use,
225
                        namespacedFunctions: $bySource($symbols[SymbolKind::Function->name]),
1 ✔
226
                        namespacedConstants: $bySource($symbols[SymbolKind::Constant->name]),
1 ✔
227
                        nameResolution: $resolution ?? 'uncertain',
1 ✔
228
                        lineLength: self::resolveLineLength($values->get('file.lineLength')),
1 ✔
229
                        tabWidth: $values->get('indentation.tabWidth')->getCountRange()[0],
1 ✔
230
                        typeAnalysis: $this->typesAvailable ? $typeAnalysis : null,
1 ✔
231
                        packageTargets: array_diff_key($config->targets, ['php' => true]),
1 ✔
232
                        plugins: array_map(
1 ✔
233
                                fn(string|Plugin $plugin) => is_string($plugin) ? $plugin : $plugin::class,
1 ✔
234
                                [...$config->plugins, ...$commandLine instanceof Config ? $commandLine->plugins : []],
1 ✔
235
                        ),
236
                        suppressionComments: $suppressionComments,
237
                        suppressionExamples: array_filter($suppressionExamples),
1 ✔
238
                        decisions: $decisions,
239
                        values: $values,
240
                        fixRisky: $fixRiskyPaths,
241
                        reportOnly: $reportOnly,
242
                        warningDecisions: self::findWarningDecisions($decisions, array_column($collected, 0), $severities),
1 ✔
243
                        overrides: $resolvedOverrides,
244
                );
245
        }
246

247

248
        /**
249
         * The decisions each of the three standards makes, resolved alone.
250
         * @return array<string, array<string, ResolvedDecision>>  standard => path => its decision
251
         * @throws ConfigurationException
252
         */
253
        public function resolveStandards(string $phpTarget): array
254
        {
255
                $standards = [];
1 ✔
256
                foreach (CorePlugin::Standards as $standard) {
1 ✔
257
                        $standards[$standard] = $this->resolve(new Config(use: ["dresscode/$standard"]), $phpTarget)->decisions;
1 ✔
258
                }
259

260
                return $standards;
1 ✔
261
        }
262

263

264
        /**
265
         * The catalogue of the registered rules, as the registry keeps it.
266
         * @throws ConfigurationException
267
         */
268
        public function getCatalogue(): Catalogue
269
        {
270
                return $this->registry->getCatalogue();
1 ✔
271
        }
272

273

274
        /**
275
         * The maps of the upgrading files of the installed packages, and the requirements of the rules of their plugins they
276
         * turn on, as layers under every other one, where `upgrading.packages` is `yes`, or where the requirement laying a
277
         * file is not `keep` (`upgrading.php.deprecatedApi` for the data of PHP). A run narrowed by `only` gets the maps of
278
         * a package or a library it names, and those of the others only where another of its names covers the map, or the
279
         * requirement laying them.
280
         * @param  array<string, ResolvedDecision>  $decisions
281
         * @param  ?list<ExpandedName>  $narrowed
282
         * @return list<array{Layer, array<string, mixed>}>
283
         * @throws ConfigurationException  where a file turns on a rule another plugin or the core brings
284
         */
285
        private function collectPackageMaps(array $decisions, ?array $narrowed): array
286
        {
287
                $named = $covered = [];
1 ✔
288
                foreach ($narrowed ?? [] as $expanded) {
1 ✔
289
                        $expanded->package ? $named[$expanded->name] = true : $covered += array_fill_keys($expanded->paths, true);
1 ✔
290
                }
291

292
                $layers = [];
1 ✔
293
                foreach ($this->upgradingData as $package) {
1 ✔
294
                        $requirement = $package->layer->decision;
1 ✔
295
                        $layer = $package->buildDecisions(function (string $map) use ($package, $requirement, $narrowed, $named, $covered): ?string {
1 ✔
296
                                $path = $this->findDataPath($map);
1 ✔
297
                                if ($path === null && !in_array($package->layer->package, $this->pluginsSkipped, true)) { // the plugin skipped says so
1 ✔
298
                                        $this->warnings[$package->layer->describe() . " $map"] = "Map `$map`, which "
1 ✔
299
                                                . $package->layer->formatReference()
1 ✔
300
                                                . ' sets, is not known to this DressCode; skipped.';
1 ✔
301
                                } elseif (
302
                                        $path !== null
1 ✔
303
                                        && !$this->getCatalogue()->find($path)?->domain instanceof Map
1 ✔
304
                                        && !$this->isOfPackagePlugin($path, $package->layer->package)
1 ✔
305
                                ) {
306
                                        throw new ConfigurationException(
1 ✔
307
                                                $package->layer->formatReference() . " turns on `$path`, which is no rule of the plugin of its package.",
1 ✔
308
                                        );
309
                                }
310

311
                                return $path !== null
1 ✔
312
                                        && ($narrowed === null
1 ✔
313
                                                || isset($named[$package->layer->package ?? ''])
1 ✔
314
                                                || isset($named[$package->package])
1 ✔
315
                                                || isset($covered[$path])
1 ✔
316
                                                || isset($covered[$requirement ?? '']))
1 ✔
317
                                        ? $path
1 ✔
318
                                        : null;
1 ✔
319
                        });
1 ✔
320
                        $laid = $requirement === null
1 ✔
321
                                ? ($decisions[self::PackagesDecision] ?? null)?->value->getFlag()
1 ✔
322
                                : ($decisions[$requirement] ?? null)?->value->isKept() === false;
1 ✔
323
                        if ($layer !== [] && $laid) {
1 ✔
324
                                $layers[] = [$package->layer, $layer];
1 ✔
325
                        }
326
                }
327

328
                return $layers;
1 ✔
329
        }
330

331

332
        /** Whether the decision is one of the rules of the plugin the package ships. */
333
        private function isOfPackagePlugin(string $path, ?string $package): bool
334
        {
335
                $section = $package === null ? null : $this->registry->findPackageSection($package);
1 ✔
336
                return $section !== null && str_starts_with($path, "$section.");
1 ✔
337
        }
338

339

340
        /**
341
         * The decision a key of a section of an upgrading file sets: a map of `upgrading.api` by its name, a map of a plugin
342
         * or a requirement it turns on by its path.
343
         */
344
        private function findDataPath(string $key): ?string
345
        {
346
                $decision = $this->getCatalogue()->find($key);
1 ✔
347
                return match (true) {
348
                        $this->getCatalogue()->find("upgrading.api.$key")?->domain instanceof Map => "upgrading.api.$key",
1 ✔
349
                        $decision?->domain instanceof Map, $decision?->isRequirement() === true => $key,
1 ✔
350
                        default => null,
1 ✔
351
                };
352
        }
353

354

355
        /**
356
         * A rule runs where one of its requirements or facts takes effect and lies in the mask of the run; otherwise it says
357
         * why it does not. A preset may decide what cannot run here; a project deciding it asked for what it cannot get,
358
         * which is an error for the types and a warning for the target and for a package, unless another rule of the
359
         * decision runs.
360
         * @param  class-string<Rule>  $class
361
         * @param  array<string, ResolvedDecision>  $decisions  those the rule declares
362
         * @param  ?InactiveReason  $ruleReason  why the rule does not run whatever its values
363
         * @param  ?\Closure(): Rule  $factory
364
         * @throws ConfigurationException
365
         */
366
        private function resolveRule(
367
                string $class,
368
                array $decisions,
369
                ?InactiveReason $ruleReason,
370
                Values $values,
371
                string $phpTarget,
372
                ?\Closure $factory,
373
                bool $fixRisky,
374
                bool $ofOverride,
375
        ): ResolvedRule
376
        {
377
                $own = array_filter($decisions, fn(ResolvedDecision $decision) => $decision->decision->kind !== DecisionKind::Parameter);
1 ✔
378
                $effective = $ruleReason === null ? array_filter($own, fn(ResolvedDecision $decision) => $decision->inactive === null) : [];
1 ✔
379
                $asked = array_filter($own, function (ResolvedDecision $decision): bool {
1 ✔
380
                        $top = $decision->findTopLayer();
1 ✔
381
                        return $top?->origin?->isProject() === true && !$top->isKept() && $decision->inactive !== null;
1 ✔
382
                });
1 ✔
383
                // a value a group gives a decision its target leaves out is skipped silently, as one of a preset; the types never are
384
                $named = array_keys(array_filter($asked, fn(ResolvedDecision $decision) => !$decision->cascaded));
1 ✔
385
                $asked = array_keys($asked);
1 ✔
386
                $info = RuleInfo::fromRule($class);
1 ✔
387
                if ($asked !== [] && $ruleReason === InactiveReason::Types) {
1 ✔
388
                        throw new ConfigurationException($this->typesAvailable
1 ✔
389
                                ? "Decision `$asked[0]` needs the types of the code; set `typeAnalysis: phpstan` in the configuration and install `phpstan/phpstan` beside DressCode."
1 ✔
390
                                : "Decision `$asked[0]` needs the types of the code, but `phpstan/phpstan` is not installed beside DressCode.", docs: 'types#enable');
1 ✔
391
                } elseif ($named !== [] && $ruleReason === InactiveReason::Php) {
1 ✔
392
                        $this->warnings[$class] = "Decision `$named[0]` needs PHP {$info->requires['php']} and the target is $phpTarget; skipped.";
1 ✔
393
                } elseif ($named !== [] && $ruleReason === InactiveReason::Package) {
1 ✔
394
                        $this->warnings[$class] = "Decision `$named[0]` needs "
1 ✔
395
                                . ($this->project->findUnmetRequirement($info->getRequiredPackages()) ?? throw new \LogicException)->format()
1 ✔
396
                                . '; skipped.';
1 ✔
397
                }
398

399
                [$reason, $message] = match (true) {
1 ✔
400
                        $effective !== []
401
                                && array_any($effective, fn(ResolvedDecision $decision) => $values->isSelected($decision->decision->path)) => [
1 ✔
402
                                        null,
1 ✔
403
                                        null,
404
                                ],
405
                        $effective !== [] => [InactiveReason::Narrowed, 'the run is narrowed to other decisions'],
1 ✔
406
                        $ruleReason === InactiveReason::Php => [
1 ✔
407
                                InactiveReason::Php,
1 ✔
408
                                "it needs PHP {$info->requires['php']} and the target is $phpTarget",
1 ✔
409
                        ],
410
                        $ruleReason === InactiveReason::Package => [InactiveReason::Package, 'it needs a package the project does not have'],
1 ✔
411
                        $ruleReason === InactiveReason::Types
1 ✔
412
                                && array_any(
1 ✔
413
                                        $own,
414
                                        fn(ResolvedDecision $decision) => $decision->decision->isRequirement() && !$decision->value->isKept(),
1 ✔
415
                                ) => [InactiveReason::Types, $this->typesAvailable
1 ✔
416
                                        ? 'it needs the types of the code and the configuration sets no types'
1 ✔
417
                                        : 'it needs the types of the code and phpstan/phpstan is not installed beside DressCode'],
1 ✔
418
                        array_any($own, fn(ResolvedDecision $decision) => $decision->layers !== []) => [
1 ✔
419
                                InactiveReason::TurnedOff,
1 ✔
420
                                'its decisions are `keep`',
1 ✔
421
                        ],
422
                        $ofOverride => [InactiveReason::OnlyOverride, 'only an override turns it on'],
1 ✔
423
                        default => [InactiveReason::NotMentioned, 'no preset or layer of the configuration names its decisions'],
1 ✔
424
                };
425
                // who said the decisive value: of a decision that takes effect, or of the last one turned off
426
                $said = $reason === null ? $effective : array_filter($own, fn(ResolvedDecision $decision) => $decision->layers !== []);
1 ✔
427
                $top = array_values($said)[0]->layers ?? [];
1 ✔
428
                $source = $top === [] ? null : $top[count($top) - 1]->origin;
1 ✔
429
                return new ResolvedRule($class, $source, $reason, $message, $factory, $fixRisky);
1 ✔
430
        }
431

432

433
        /**
434
         * The severity a layer says of each requirement its names cover, the most specific name winning: a decision, a
435
         * deeper group, a shallower one, a section, the class of a rule, a preset.
436
         * @param  array<string, string>  $names  name => `warning` or `error`
437
         * @return array<string, array{int, string}>  path => the rank of the name and the severity
438
         * @throws ConfigurationException
439
         */
440
        private function collectSeverity(array $names): array
441
        {
442
                $severity = $by = [];
1 ✔
443
                foreach ($names as $name => $value) {
1 ✔
444
                        $expanded = $this->expandName($name);
1 ✔
445
                        $paths = array_filter(
1 ✔
446
                                $expanded->paths,
1 ✔
447
                                fn(string $path) => $this->getCatalogue()->find($path)?->kind !== DecisionKind::Parameter,
1 ✔
448
                        );
449
                        if ($paths === []) {
1 ✔
450
                                throw new ConfigurationException("Name `$name` in `severity` covers no decision that reports; a parameter has no severity of its own.");
1 ✔
451
                        }
452

453
                        $rank = match (true) {
1 ✔
454
                                $expanded->preset => 0,
1 ✔
455
                                $expanded->rule !== null => 1,
1 ✔
456
                                $this->getCatalogue()->find($name) !== null => PHP_INT_MAX,
1 ✔
457
                                default => 1 + count(explode('.', $expanded->name)),
1 ✔
458
                        };
459
                        foreach ($paths as $path) {
1 ✔
460
                                [$was, $wasValue] = $severity[$path] ?? [-1, null];
1 ✔
461
                                if ($was === $rank && $wasValue !== $value) {
1 ✔
462
                                        throw new ConfigurationException("Names `{$by[$path]}` and `$name` in `severity` say two severities of `$path`; name it alone.");
1 ✔
463
                                } elseif ($was < $rank) {
1 ✔
464
                                        $severity[$path] = [$rank, $value];
1 ✔
465
                                        $by[$path] = $name;
1 ✔
466
                                }
467
                        }
468
                }
469

470
                return $severity;
1 ✔
471
        }
472

473

474
        /**
475
         * The requirements whose violations only warn: a severity holds for a decision whose value the layer saying it, or
476
         * one below it, said, so a layer writing the value anew without a severity makes it an error again.
477
         * @param  array<string, ResolvedDecision>  $decisions
478
         * @param  list<Layer>  $layers  from the lowest
479
         * @param  list<array<string, array{int, string}>>  $severities  of each layer, by path
480
         * @return array<string, true>
481
         */
482
        private static function findWarningDecisions(array $decisions, array $layers, array $severities): array
483
        {
484
                $warnings = [];
1 ✔
485
                foreach ($decisions as $path => $decision) {
1 ✔
486
                        $top = $decision->findTopLayer()?->origin;
1 ✔
487
                        $from = $top === null ? 0 : max(0, (int) array_search($top, $layers, strict: true));
1 ✔
488
                        for ($i = count($layers) - 1; $i >= $from; $i--) {
1 ✔
489
                                if (isset($severities[$i][$path])) {
1 ✔
490
                                        if ($severities[$i][$path][1] === 'warning') {
1 ✔
491
                                                $warnings[$path] = true;
1 ✔
492
                                        }
493

494
                                        break;
1 ✔
495
                                }
496
                        }
497
                }
498

499
                return $warnings;
1 ✔
500
        }
501

502

503
        /**
504
         * The paths the decisions of the run are narrowed to, those the names of `only` stand for.
505
         * @param  list<ExpandedName>  $narrowed
506
         * @return list<string>
507
         */
508
        private function collectSelection(array $narrowed): array
509
        {
510
                return array_values(array_unique(array_merge(...array_map(fn(ExpandedName $name) => $name->paths, $narrowed))));
1 ✔
511
        }
512

513

514
        /**
515
         * The decisions a name of `suppressionComments` silences.
516
         * @return list<string>
517
         * @throws ConfigurationException
518
         */
519
        private function resolveSuppressedName(string $name): array
520
        {
521
                return $this->registry->expandSuppressedName($name)
1 ✔
522
                        ?: throw new ConfigurationException("`suppressionComments` names `$name`, which is no decision, section or rule.");
1 ✔
523
        }
524

525

526
        /**
527
         * Adds the functions and the constants the namespaces of a layer declare, each spelled the way the first layer
528
         * naming it spells it.
529
         * @param  array<string, array<string, array{string, string}>>  $symbols
530
         * @param  array{functions: list<string>, constants: list<string>}  $namespaces
531
         */
532
        private static function addSymbols(array &$symbols, array $namespaces, string $layer): void
533
        {
534
                foreach ([[SymbolKind::Function, 'functions'], [SymbolKind::Constant, 'constants']] as [$kind, $key]) {
1 ✔
535
                        foreach ($namespaces[$key] as $name) {
1 ✔
536
                                $symbols[$kind->name][self::toSymbolKey($kind, $name)] ??= [$name, $layer];
1 ✔
537
                        }
538
                }
539
        }
1 ✔
540

541

542
        /**
543
         * The key two spellings of one symbol share, the way PHP reads them: a function in any letter case, a constant
544
         * in any letter case of its namespace but not of its own name.
545
         */
546
        public static function toSymbolKey(SymbolKind $kind, string $name): string
547
        {
548
                $name = ltrim($name, '\\');
1 ✔
549
                $pos = (int) strrpos($name, '\\');
1 ✔
550
                return $kind === SymbolKind::Constant
1 ✔
551
                        ? strtolower(substr($name, 0, $pos)) . substr($name, $pos)
1 ✔
552
                        : strtolower($name);
1 ✔
553
        }
554

555

556
        /**
557
         * The versions the code is checked for and the lowest of them, the one a rule asks about. A target older than the
558
         * version the rules are tested from stays as it is, with a warning, the rules of what came later leaving its code
559
         * alone; one without a lowest version is checked as that version.
560
         * @return array{string, string}
561
         */
562
        private function resolvePhpTarget(string $target): array
563
        {
564
                $version = Versions::findLowestVersion($target);
1 ✔
565
                if ($version === null) {
1 ✔
UNCOV
566
                        $this->warnings['php'] = "The target PHP $target names no oldest version; the code is checked as PHP " . Config::MinPhpVersion
×
UNCOV
567
                                . ', so a fix may write syntax the target does not have.';
×
UNCOV
568
                        return [Config::MinPhpVersion, Config::MinPhpVersion];
×
569

570
                } elseif (version_compare($version, Config::MinPhpVersion, '<')) {
1 ✔
571
                        $this->warnings['php'] = "The target PHP $version is older than " . Config::MinPhpVersion
1 ✔
572
                                . ', which DressCode tests; the fixes of PHP 8 constructs stay off.';
1 ✔
573
                }
574

575
                return [$target, $version];
1 ✔
576
        }
577

578

579
        /** The characters of a level of indentation the unit names, a tab where it is `keep`. */
580
        private static function resolveIndent(Value $unit): string
581
        {
582
                return $unit->isKept() || $unit->getWord() === 'tab' ? "\t" : str_repeat(' ', (int) $unit->getWord());
1 ✔
583
        }
584

585

586
        /** The line ending the decision names; null for the one each file uses most. */
587
        private static function resolveLineEnding(Value $lineEnding): ?string
588
        {
589
                return match ($lineEnding->isKept() ? null : $lineEnding->getWord()) {
1 ✔
590
                        'LF' => "\n",
1 ✔
591
                        'CRLF' => "\r\n",
1 ✔
592
                        default => null,
1 ✔
593
                };
594
        }
595

596

597
        /** The widest line, null for none. */
598
        private static function resolveLineLength(Value $length): ?int
599
        {
600
                return $length->content === 'none' ? null : $length->getCountRange()[0];
1 ✔
601
        }
602

603

604
        /**
605
         * The profiles that decide for a file matching the overrides, lowest first, each with the name an error or an origin
606
         * is told by.
607
         * @param  list<int>  $overrides
608
         * @return list<array{Layer, Profile}>
609
         */
610
        private static function listProfiles(Config $config, array $overrides, ?Profile $commandLine = null): array
611
        {
612
                $profiles = [[new Layer(LayerKind::Configuration), $config]];
1 ✔
613
                foreach ($overrides as $index) {
1 ✔
614
                        $profiles[] = [
1 ✔
615
                                new Layer(LayerKind::Override, implode(', ', $config->overrides[$index]->paths)),
1 ✔
616
                                $config->overrides[$index]->profile,
1 ✔
617
                        ];
618
                }
619

620
                if ($commandLine !== null) {
1 ✔
621
                        $profiles[] = [new Layer(LayerKind::CommandLine), $commandLine];
1 ✔
622
                }
623

624
                return $profiles;
1 ✔
625
        }
626

627

628
        /**
629
         * The profiles as layers, lowest first: each of them above what it uses, in the order it names them, and a preset
630
         * where it is named first; what a profile names that is already laid, it names for nothing.
631
         * @param  list<array{Layer, Profile}>  $profiles  who says it and what it says
632
         * @return array{layers: list<array{Layer, Profile}>, repeated: list<array{Layer, Layer, Layer}>}  the layers, each
633
         *   who says it and what it says; and every entry named for nothing, as its layer, the one that laid it and the one
634
         *   that named it again
635
         * @throws ConfigurationException
636
         */
637
        private function collectLayers(array $profiles): array
638
        {
639
                $layers = $visited = $repeated = [];
1 ✔
640
                foreach ($profiles as [$layer, $profile]) {
1 ✔
641
                        $this->collectUsed($profile, $layer, $layers, $visited, $repeated);
1 ✔
642
                        $layers[] = [$layer, $profile];
1 ✔
643
                }
644

645
                return ['layers' => $layers, 'repeated' => $repeated];
1 ✔
646
        }
647

648

649
        /**
650
         * Lays the presets the profile uses, each above what it uses in turn, once, where it is named first; a preset
651
         * that comes back to itself through what it uses is an error, unlike one named again by another layer, which
652
         * does nothing.
653
         * @param  list<array{Layer, Profile}>  $layers
654
         * @param  array<string, Layer>  $visited  the name of a preset => the layer that laid it
655
         * @param  list<array{Layer, Layer, Layer}>  $repeated
656
         * @throws ConfigurationException
657
         */
658
        private function collectUsed(Profile $profile, Layer $source, array &$layers, array &$visited, array &$repeated): void
659
        {
660
                foreach ($profile->use as $entry) {
1 ✔
661
                        if ($this->registry->isPluginPackage($entry)) { // it lets the plugin of the package in, which is no layer
1 ✔
662
                                continue;
1 ✔
663
                        }
664

665
                        try {
666
                                // a preset by its name, or a file of the same shape by its path, which is its name too
667
                                $name = str_ends_with($entry, '.neon')
1 ✔
668
                                        ? NeonReader::resolvePresetFile($entry, $this->root)
1 ✔
669
                                        : $this->registry->resolvePreset($entry);
1 ✔
670
                                $file = $this->registry->presets[$name] ?? $name;
1 ✔
671
                        } catch (ConfigurationException $e) {
1 ✔
672
                                throw self::locate($e, $source);
1 ✔
673
                        } catch (\InvalidArgumentException $e) {
1 ✔
674
                                throw self::locate(new ConfigurationException($e->getMessage(), previous: $e), $source);
1 ✔
675
                        }
676

677
                        $layer = new Layer(LayerKind::Preset, $name);
1 ✔
678
                        if (in_array($name, $this->using, true)) {
1 ✔
679
                                $cycle = implode('`, `', array_slice($this->using, array_search($name, $this->using, strict: true) + 1));
1 ✔
680
                                throw new ConfigurationException(($file === $name ? 'Preset file' : 'Preset') . " `$name` uses itself through `$cycle`; a preset cannot come back to itself.");
1 ✔
681
                        } elseif (isset($visited[$name])) {
1 ✔
682
                                $repeated[] = [$layer, $visited[$name], $source];
1 ✔
683
                                continue;
1 ✔
684
                        }
685

686
                        $visited[$name] = $source;
1 ✔
687
                        $preset = $this->presetFiles[$file] ??= NeonReader::readPreset($file, $file === $name ? null : $name);
1 ✔
688
                        $this->using[] = $name;
1 ✔
689
                        try {
690
                                $this->collectUsed($preset, $layer, $layers, $visited, $repeated);
1 ✔
691
                        } finally {
1 ✔
692
                                array_pop($this->using);
1 ✔
693
                        }
694

695
                        $layers[] = [$layer, $preset];
1 ✔
696
                }
697
        }
1 ✔
698

699

700
        /**
701
         * An entry named again where a layer below already laid it does nothing, and the run says so.
702
         * @param  list<array{Layer, Layer, Layer}>  $repeated
703
         */
704
        private function warnRepeated(array $repeated): void
705
        {
706
                foreach ($repeated as [$layer, $laidBy, $namedBy]) {
1 ✔
707
                        // what a preset uses is not the project's to change, and the command line reaches what an override does not
708
                        if (
709
                                $namedBy->kind !== LayerKind::Preset
1 ✔
710
                                && !($laidBy->kind === LayerKind::Override && $namedBy->kind === LayerKind::CommandLine)
1 ✔
711
                        ) {
712
                                $this->warnings['repeated ' . $layer->describe() . ' ' . $namedBy->describe()] = ucfirst($namedBy->formatReference())
1 ✔
713
                                        . ' uses ' . $layer->formatReference()
1 ✔
714
                                        . ', which ' . $laidBy->formatReference() . ' already brings; the entry does nothing.';
1 ✔
715
                        }
716
                }
717
        }
1 ✔
718

719

720
        /** An error said in a layer the reader has to be sent to, named in front of it; the configuration needs no pointing at. */
721
        private static function locate(ConfigurationException $e, Layer $layer): ConfigurationException
722
        {
723
                return $layer->kind === LayerKind::Configuration
1 ✔
724
                        ? $e
1 ✔
725
                        : new ConfigurationException(ucfirst($layer->formatReference()) . ": {$e->getMessage()}", $e->docs, $e);
1 ✔
726
        }
727

728

729
        /**
730
         * The rules a run narrowed by `only` keeps, per name it was given.
731
         * @param  list<string>  $names
732
         * @return list<ExpandedName>
733
         * @throws ConfigurationException
734
         */
735
        private function resolveOnly(array $names): array
736
        {
737
                return array_map($this->expandName(...), $names);
1 ✔
738
        }
739

740

741
        /**
742
         * What a name of `only`, `fixRisky` or `severity` stands for: a decision or a section for the decisions under it,
743
         * a package of upgrading data for what its files set, a library for what the files about it set, both for a name of
744
         * both, a rule for its own, a preset for every decision it and its parents make, each with the rules owning them. A
745
         * section named like a preset is written `section.*`, the bare name being refused as both.
746
         * @throws ConfigurationException
747
         */
748
        private function expandName(string $name): ExpandedName
749
        {
750
                $package = $this->findDataPackage($name);
1 ✔
751
                if ($package !== null) {
1 ✔
752
                        $paths = [];
1 ✔
753
                        foreach ($this->upgradingData as $data) {
1 ✔
754
                                if ($data->layer->package === $package || $data->package === $package) {
1 ✔
755
                                        $keys = [...array_keys($data->maps), ...array_keys($data->requirements)];
1 ✔
756
                                        array_push($paths, ...array_filter(array_map($this->findDataPath(...), $keys)));
1 ✔
757
                                }
758
                        }
759

760
                        $paths = array_values(array_unique($paths));
1 ✔
761
                        $rules = array_merge(...array_map($this->getCatalogue()->getRulesOf(...), $paths));
1 ✔
762
                        return new ExpandedName($package, false, null, array_values(array_unique($rules)), $paths, package: true);
1 ✔
763
                }
764

765
                $section = str_ends_with($name, '.*') ? substr($name, 0, -2) : null;
1 ✔
766
                $paths = array_keys($this->getCatalogue()->getDecisionsUnder($section ?? $name));
1 ✔
767
                $preset = $paths !== [] && $section === null && !str_contains($name, '.') ? $this->registry->findPreset($name) : null;
1 ✔
768
                if ($preset !== null) {
1 ✔
769
                        throw new ConfigurationException("Name `$name` is both a section of decisions and the preset `$preset`; write `$name.*` for the section or `$preset` for the preset.");
1 ✔
770
                }
771

772
                $preset = null;
1 ✔
773
                if ($paths === [] && $section !== null) {
1 ✔
774
                        throw new ConfigurationException("Unknown section `$section`.");
1 ✔
775
                } elseif ($paths === [] && in_array($name, $this->registry->rules, true)) {
1 ✔
776
                        $requirements = array_filter(
1 ✔
777
                                $this->getCatalogue()->getDecisionsOf($name),
1 ✔
778
                                fn(Decision $decision) => $decision->kind !== DecisionKind::Parameter,
1 ✔
779
                        );
780
                        return new ExpandedName($name, false, $name, [$name], array_keys($requirements));
1 ✔
781
                } elseif ($paths === [] && class_exists($name) && is_subclass_of($name, Rule::class)) {
1 ✔
782
                        throw new ConfigurationException("Rule `$name` is not registered; add it to `rules` of the configuration.");
1 ✔
783
                } elseif ($paths === []) {
1 ✔
784
                        $preset = $this->registry->findPreset($name) ?? throw $this->registry->createUnknownNameException($name);
1 ✔
785
                        foreach ($this->collectLayers([[new Layer(LayerKind::Caller), new Profile(use: [$preset])]])['layers'] as [, $profile]) {
1 ✔
786
                                array_push($paths, ...$this->collectPaths($profile->decisions));
1 ✔
787
                        }
788
                }
789

790
                $paths = array_values(array_unique($paths));
1 ✔
791
                $rules = array_merge(...array_map($this->getCatalogue()->getRulesOf(...), $paths));
1 ✔
792
                return new ExpandedName($preset ?? $section ?? $name, $preset !== null, null, array_values(array_unique($rules)), $paths);
1 ✔
793
        }
794

795

796
        /**
797
         * The full name of the installed package the name stands for, one shipping upgrading files or one they are about,
798
         * one of the core without its vendor too.
799
         */
800
        private function findDataPackage(string $name): ?string
801
        {
802
                $names = [$name, PluginRegistry::qualify($name)];
1 ✔
803
                foreach ($this->upgradingData as $data) {
1 ✔
804
                        if ($data->layer->name !== null && in_array($data->layer->package, $names, true)) {
1 ✔
805
                                return $data->layer->package;
1 ✔
806
                        } elseif (in_array($data->package, $names, true)) {
1 ✔
807
                                return $data->package;
1 ✔
808
                        }
809
                }
810

811
                return null;
1 ✔
812
        }
813

814

815
        /**
816
         * The paths of the decisions a layer makes, every one under a structure it makes as a whole.
817
         * @param  array<mixed>  $tree
818
         * @return list<string>
819
         */
820
        private function collectPaths(array $tree, string $prefix = ''): array
821
        {
822
                $paths = [];
1 ✔
823
                foreach ($tree as $key => $value) {
1 ✔
824
                        $path = $prefix . $key;
1 ✔
825
                        if ($this->getCatalogue()->find($path) !== null) {
1 ✔
826
                                $paths[] = $path;
1 ✔
827
                        } elseif (is_array($value)) {
1 ✔
828
                                array_push($paths, ...$this->collectPaths($value, "$path."));
1 ✔
829
                        } else {
830
                                array_push($paths, ...array_keys($this->getCatalogue()->getDecisionsUnder($path)));
1 ✔
831
                        }
832
                }
833

834
                return $paths;
1 ✔
835
        }
836

837

838
        /**
839
         * A name of `only` that lets in nothing that runs would make a run that checks nothing and says it is clean, and
840
         * a section or a preset of which only some rules run here would make one that checks less than it says; a rule that
841
         * runs only where an override enables it counts as running.
842
         * @param  list<ExpandedName>  $narrowed
843
         * @param  array<class-string<Rule>, ResolvedRule>  $active
844
         * @param  array<class-string<Rule>, ResolvedRule>  $inactive
845
         * @param  array<class-string<Rule>, true>  $ofOverrides
846
         * @param  list<string>  $use  the presets the run lays
847
         * @throws ConfigurationException
848
         */
849
        private function checkOnly(array $narrowed, array $active, array $inactive, array $ofOverrides, array $use): void
850
        {
851
                $skipped = [];
1 ✔
852
                foreach ($narrowed as $expanded) {
1 ✔
853
                        [$class, $rules] = [$expanded->rule, $expanded->rules];
1 ✔
854
                        $running = array_filter($rules, fn(string $rule) => isset($active[$rule]) || isset($ofOverrides[$rule]));
1 ✔
855
                        // a name whose rules the project cannot run, too new for its target or for its packages, is skipped, so that
856
                        // one command of `--only` serves projects of several targets
857
                        if (
858
                                !$running
1 ✔
859
                                && $rules !== []
1 ✔
860
                                && array_all($rules, fn(string $rule) => in_array(
1 ✔
861
                                        $inactive[$rule]->inactiveReason ?? null,
1 ✔
862
                                        [InactiveReason::Php, InactiveReason::Package],
1 ✔
863
                                        true,
1 ✔
864
                                ))
1 ✔
865
                        ) {
866
                                $skipped[$expanded->name] = [
1 ✔
867
                                        'Option `--only` names ' . ($class === null ? $expanded->format() : "rule `$class`")
1 ✔
868
                                        . ", which cannot run here: {$inactive[$rules[array_key_first($rules)]]->inactiveMessage}",
1 ✔
869
                                        $rules,
1 ✔
870
                                ];
871
                                continue;
1 ✔
872
                        }
873

874
                        if ($class !== null) {
1 ✔
875
                                if (!$running) {
1 ✔
876
                                        throw new ConfigurationException("Option `--only` names rule `$class`, which cannot run here: {$inactive[$class]->inactiveMessage}.");
1 ✔
877
                                }
878

879
                                continue;
1 ✔
880
                        }
881

882
                        // left out is what the project turned off, and where it does not use the name what the name would bring; a rule
883
                        // its standard turns off or that cannot run here, too new for the target or needing the types, is not
884
                        $collective = PluginRegistry::abbreviate($expanded->name);
1 ✔
885
                        $laid = in_array($collective, array_map(PluginRegistry::abbreviate(...), $use), true);
1 ✔
886
                        $left = array_filter($rules, fn(string $rule) => match ($inactive[$rule]->inactiveReason ?? null) {
1 ✔
887
                                InactiveReason::TurnedOff => $inactive[$rule]->source?->isProject() === true,
1 ✔
888
                                InactiveReason::NotMentioned => !$laid,
1 ✔
889
                                default => false,
1 ✔
890
                        });
1 ✔
891
                        // a preset the configuration does not use is brought by `--use`, a decision it does not make by `--set`
892
                        $hint = match (true) {
1 ✔
893
                                $expanded->preset => "`--use $collective --only $collective` runs all its rules",
1 ✔
894
                                $expanded->package
1 ✔
895
                                        => 'its upgrading files reach no version of a library the project has, or `upgrading.packages` is not `yes`',
1 ✔
896
                                $this->getCatalogue()->find($collective) !== null => "`--set $collective=<value>` decides it for the run",
1 ✔
897
                                default => '`--set <path>=<value>` decides one of them for the run',
1 ✔
898
                        };
899
                        if (!$running) {
1 ✔
900
                                throw new ConfigurationException('Option `--only` names ' . $expanded->format() . ', which has no rule that runs here' . ($laid ? '.' : "; $hint."));
1 ✔
901
                        } elseif ($left) {
1 ✔
902
                                // a rule left out is named by its requirements, which is what the user writes
903
                                $names = array_map(fn(string $path) => "`$path`", array_keys(array_filter(
1 ✔
904
                                        array_merge(...array_map(fn(string $rule) => $this->getCatalogue()->getDecisionsOf($rule), array_values($left))),
1 ✔
905
                                        fn(Decision $decision) => $decision->kind !== DecisionKind::Parameter,
1 ✔
906
                                )));
907
                                $this->warnings["only $expanded->name"] = 'Option `--only` keeps ' . count($running) . ' of the ' . (count(
1 ✔
908
                                        $running,
1 ✔
909
                                ) + count($left))
1 ✔
910
                                        . ' rules of ' . $expanded->format() . ' that may run here'
1 ✔
911
                                        . ($laid || !$expanded->preset
1 ✔
912
                                                ? ', without ' . implode(', ', array_slice($names, 0, 5)) . (count($names) > 5
1 ✔
913
                                                        ? ' and ' . (count($names) - 5) . ' more'
1 ✔
914
                                                        : '')
1 ✔
915
                                                        . ($laid ? ', which the configuration turns off.' : ", which the configuration does not decide; $hint.")
1 ✔
916
                                                : "; $hint.");
1 ✔
917
                        }
918
                }
919

920
                if ($skipped !== [] && count($skipped) === count($narrowed)) {
1 ✔
921
                        throw new ConfigurationException(reset($skipped)[0] . '.');
1 ✔
922
                }
923

924
                foreach ($skipped as $name => [$message, $rules]) {
1 ✔
925
                        // a rule whose decision the project wrote is said to be skipped already
926
                        if (!array_all($rules, fn(string $rule) => isset($this->warnings[$rule]))) {
1 ✔
927
                                $this->warnings["only $name"] = "$message; it is skipped.";
1 ✔
928
                        }
929
                }
930
        }
1 ✔
931

932

933
        /**
934
         * A name in fixRisky or reportOnly whose rules run nowhere, not even where an override turns them on, makes the entry
935
         * a line that does nothing, which is worth a warning.
936
         * @param  array<class-string<Rule>, ResolvedRule>  $active
937
         * @param  array<class-string<Rule>, true>  $ofOverrides
938
         * @throws ConfigurationException
939
         */
940
        private function checkFixPolicies(Config $config, array $active, array $ofOverrides): void
941
        {
942
                foreach (self::listProfiles($config, array_keys($config->overrides)) as [$layer, $profile]) {
1 ✔
943
                        foreach (['fixRisky' => $profile->fixRisky, 'reportOnly' => $profile->reportOnly] as $key => $entries) {
1 ✔
944
                                foreach ($entries as $entry) {
1 ✔
945
                                        try {
946
                                                $expanded = $this->expandName($entry);
1 ✔
UNCOV
947
                                        } catch (ConfigurationException $e) {
×
UNCOV
948
                                                throw self::locate($e, $layer);
×
949
                                        }
950

951
                                        if (!array_filter($expanded->rules, fn(string $class) => isset($active[$class]) || isset($ofOverrides[$class]))) {
1 ✔
952
                                                $this->warnings["$key $expanded->name"] = ucfirst($expanded->format())
1 ✔
953
                                                        . " is named in `$key` but runs nowhere; the entry does nothing.";
1 ✔
954
                                        }
955
                                }
956
                        }
957
                }
958
        }
1 ✔
959
}
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