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

dg / dresscode / 42624378945

09 Nov 2026 01:18PM UTC coverage: 97.024% (-0.8%) from 97.794%
42624378945

push

github

dg
cli: the hidden option --profile writes where the time of a run went, the workers included

`--profile <file>` writes as JSON where the time of a run went, in nanoseconds: the phases (the start of the process,
the start of the container of PHPStan or of a derived one and its scopes, the parse, the passes, the gaps, the print,
the cycle collection, the run as a whole), every rule by the time of its callbacks, how often they ran and how often
they changed the tree, every gap rule by the time of its claims, every file with its size, rounds and passes, and the
peak memory of every process. A worker measures its own files and hands that over with every result and the parent
adds it up, so the totals do not depend on the number of workers. A run with the option leaves the result cache out,
a file served from the cache having nothing to measure.

It says where the time of a run goes, not only how much of it: a comparison of two revisions then names the rule or
the claim that moved. Without the option the engine only asks whether there is a profiler, and wraps a claim in
a measurement only when there is one.

137 of 148 new or added lines in 14 files covered. (92.57%)

160 existing lines in 36 files now uncovered.

30283 of 31212 relevant lines covered (97.02%)

0.97 hits per line

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

96.3
/src/Config.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;
9

10
use PhpSyntax\Nodes\FileNode;
11

12

13
/**
14
 * The configuration of a project, written as dresscode.neon or dresscode.php, whose keys are the parameters here: the
15
 * profile of the whole project, the overrides for parts of its tree, and the scope of a run, what it checks and what it
16
 * keeps. A key left out keeps its default.
17
 */
18
final readonly class Config extends Profile
19
{
20
        /** dependencies, temporary and log directories, and anything dot-prefixed (.git, .idea, .scratch) */
21
        public const DefaultExcludePaths = ['vendor', 'node_modules', 'temp', 'tmp', 'log', '.*'];
22

23
        /**
24
         * the oldest version the rules are tested for; a rule asks whether the target has what it already has only where it
25
         * writes that for an older target
26
         * @internal
27
         */
28
        public const MinPhpVersion = '8.0';
29

30
        /** the version the rules target when neither the configuration nor a composer.json says one */
31
        public const DefaultPhpVersion = '8.0';
32

33
        /** @var list<string>  patterns relative to the root: the default ones and those the configuration adds, each once */
34
        public array $excludePaths;
35

36
        /** @var ?\Closure(string, string): bool  files left out by their content and path */
37
        public ?\Closure $skipWhen;
38

39
        /**
40
         * @var array<class-string, ?\Closure(FileNode, string): object>  analysis => its factory given the file and its
41
         * path, or null when the engine builds it with the file or with nothing
42
         */
43
        public array $analyses;
44

45
        /** @var list<class-string<Plugin>|Plugin>  the plugins `use` names, which make their rules, presets and analyses known */
46
        public array $plugins;
47

48
        /**
49
         * @var array<class-string<Rule>, ?\Closure(): Rule>  the rules of the project, each with its factory or null where
50
         * the engine builds it
51
         */
52
        public array $rules;
53

54

55
        /**
56
         * @param list<string|Plugin> $use  presets by name, files of the same shape by their path, and plugins by class or as objects
57
         * @param array<int|class-string<Rule>, class-string<Rule>|\Closure(): Rule> $rules  the rules of the project, each by its
58
         *   class, or its class with the factory of a rule with dependencies
59
         * @param array{functions?: list<string>, constants?: list<string>} $namespaces
60
         * @param list<string> $fixRisky
61
         * @param list<string> $reportOnly
62
         * @param array<string, string> $targets  `php` and the packages, each => the version the code is written for
63
         * @param array<string, string> $severity
64
         * @param array<string, string|list<string>|array{decisions: string|list<string>, example?: string}> $suppressionComments
65
         * @param list<string> $excludePaths  left out of the run on top of the default list
66
         * @param ?callable(string $content, string $path): bool $skipWhen
67
         * @param array<string|int, string|callable(FileNode, string): object> $analyses  a class the engine builds itself, or
68
         *   a class with its factory given the file and its path
69
         * @param array<string, mixed> $decisions
70
         */
71
        public function __construct(
72
                array $use = [],
73
                array $rules = [],
74
                array $targets = [],
75
                array $namespaces = [],
76
                ?string $nameResolution = null,
77
                array $fixRisky = [],
78
                array $reportOnly = [],
79
                array $severity = [],
80
                array $suppressionComments = [],
81
                /** @var list<Override> */
82
                public array $overrides = [],
1 ✔
83
                /** @var list<string>  files and directories relative to the root, checked when the command line names none */
84
                public array $paths = [],
1 ✔
85
                array $excludePaths = [],
86
                /** @var list<string>  the extensions of the files to check, without a dot */
87
                public array $fileExtensions = ['php'],
1 ✔
88
                ?callable $skipWhen = null,
89
                /**
90
                 * .neon or .php file of violations left unreported, relative to the root, which must exist; `dresscode baseline`
91
                 * writes it, and without it `dresscode-baseline.*` of the root where there is one
92
                 */
93
                public ?string $baseline = null,
1 ✔
94
                public ?string $cacheDir = null,
1 ✔
95
                array $analyses = [],
96
                /** `'phpstan'` takes the types of the code from the PHPStan of the project; without it no rule that needs them runs */
97
                public ?string $typeAnalysis = null,
1 ✔
98
                /**
99
                 * the address of the page of each rule of the project, `{slug}` standing for its class without the suffix, the first
100
                 * letter in lower case
101
                 */
102
                public ?string $ruleUrl = null,
1 ✔
103
                array $decisions = [],
104
        ) {
105
                $plugins = array_filter($use, fn($entry) => $entry instanceof Plugin || is_subclass_of($entry, Plugin::class));
1 ✔
106
                parent::__construct(
1 ✔
107
                        array_values(array_diff_key($use, $plugins)),
1 ✔
108
                        $targets,
109
                        $namespaces,
110
                        $nameResolution,
111
                        $fixRisky,
112
                        $reportOnly,
113
                        $severity,
114
                        $suppressionComments,
115
                        $decisions,
116
                );
117
                $this->plugins = array_values($plugins);
1 ✔
118
                $this->rules = Config\ManifestFields::normalizeRules($rules, load: true);
1 ✔
119
                if ($typeAnalysis !== null && $typeAnalysis !== 'phpstan') {
1 ✔
120
                        throw new \InvalidArgumentException("The type analysis must be `phpstan`, `$typeAnalysis` given.");
1 ✔
121
                }
122

123
                // a package is targeted in place of the lowest version its constraint allows, so that code is fixed for a version
124
                // before the project moves to it
125
                foreach (array_diff_key($targets, ['php' => true]) as $package => $version) {
1 ✔
126
                        if (!preg_match('~^[a-z0-9_.-]+/[a-z0-9_.-]+$~D', $package)) {
1 ✔
UNCOV
127
                                throw new \InvalidArgumentException("Invalid target `$package`, `php` or the name of a package is expected.");
×
128
                        } elseif (!Config\Versions::isVersion($version)) {
1 ✔
129
                                throw new \InvalidArgumentException("Invalid version `$version` of package `$package`.");
1 ✔
130
                        }
131
                }
132

133
                Config\ManifestFields::checkRuleUrl($ruleUrl);
1 ✔
134
                Config\ManifestFields::checkGlobs($excludePaths, 'excludePaths');
1 ✔
135

136
                $this->excludePaths = array_values(array_unique([...self::DefaultExcludePaths, ...$excludePaths]));
1 ✔
137
                $this->skipWhen = $skipWhen === null ? null : $skipWhen(...);
1 ✔
138
                $this->analyses = Config\ManifestFields::normalizeAnalyses($analyses);
1 ✔
139
        }
1 ✔
140

141

142
        /**
143
         * The factories of the rules of the project that the configuration builds itself.
144
         * @return array<class-string<Rule>, \Closure(): Rule>
145
         */
146
        public function getRuleFactories(): array
147
        {
148
                return array_filter($this->rules);
1 ✔
149
        }
150
}
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