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

keradus / PHP-CS-Fixer / 22042339290

15 Feb 2026 08:14PM UTC coverage: 92.957% (-0.2%) from 93.171%
22042339290

push

github

keradus
test: check PHP env in CI jobs

29302 of 31522 relevant lines covered (92.96%)

44.04 hits per line

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

91.38
/src/Config.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of PHP CS Fixer.
7
 *
8
 * (c) Fabien Potencier <fabien@symfony.com>
9
 *     Dariusz Rumiński <dariusz.ruminski@gmail.com>
10
 *
11
 * This source file is subject to the MIT license that is bundled
12
 * with this source code in the file LICENSE.
13
 */
14

15
namespace PhpCsFixer;
16

17
use PhpCsFixer\Config\RuleCustomisationPolicyAwareConfigInterface;
18
use PhpCsFixer\Config\RuleCustomisationPolicyInterface;
19
use PhpCsFixer\Fixer\FixerInterface;
20
use PhpCsFixer\RuleSet\RuleSetDefinitionInterface;
21
use PhpCsFixer\Runner\Parallel\ParallelConfig;
22
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;
23

24
/**
25
 * @author Fabien Potencier <fabien@symfony.com>
26
 * @author Katsuhiro Ogawa <ko.fivestar@gmail.com>
27
 * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
28
 *
29
 * @no-named-arguments Parameter names are not covered by the backward compatibility promise.
30
 *
31
 * @api-extendable
32
 */
33
class Config implements ConfigInterface, ParallelAwareConfigInterface, UnsupportedPhpVersionAllowedConfigInterface, CustomRulesetsAwareConfigInterface, RuleCustomisationPolicyAwareConfigInterface
34
{
35
    /**
36
     * @var non-empty-string
37
     */
38
    private string $cacheFile = '.php-cs-fixer.cache';
39

40
    /**
41
     * @var list<FixerInterface>
42
     */
43
    private array $customFixers = [];
44

45
    /**
46
     * @var array<string, RuleSetDefinitionInterface>
47
     */
48
    private array $customRuleSets = [];
49

50
    /**
51
     * @var null|iterable<\SplFileInfo>
52
     */
53
    private ?iterable $finder = null;
54

55
    private string $format;
56

57
    private bool $hideProgress = false;
58

59
    /**
60
     * @var non-empty-string
61
     */
62
    private string $indent = '    ';
63

64
    private bool $isRiskyAllowed = false;
65

66
    /**
67
     * @var non-empty-string
68
     */
69
    private string $lineEnding = "\n";
70

71
    private string $name;
72

73
    private ParallelConfig $parallelConfig;
74

75
    private ?string $phpExecutable = null;
76

77
    /**
78
     * @TODO: 4.0 - update to @PER
79
     *
80
     * @var array<string, array<string, mixed>|bool>
81
     */
82
    private array $rules;
83

84
    private bool $usingCache = true;
85

86
    private bool $isUnsupportedPhpVersionAllowed = false;
87

88
    private ?RuleCustomisationPolicyInterface $ruleCustomisationPolicy = null;
89

90
    public function __construct(string $name = 'default')
91
    {
92
        $this->name = $name.(Future::isFutureModeEnabled() ? ' (future mode)' : '');
18✔
93
        $this->rules = Future::getV4OrV3(['@PER-CS' => true], ['@PSR12' => true]); // @TODO 4.0 | 3.x switch to '@auto' for v4
18✔
94
        $this->format = Future::getV4OrV3('@auto', 'txt');
18✔
95
        $this->parallelConfig = ParallelConfigFactory::detect();
18✔
96

97
        // @TODO 4.0 cleanup
98
        if (false !== getenv('PHP_CS_FIXER_IGNORE_ENV')) {
18✔
99
            $this->isUnsupportedPhpVersionAllowed = filter_var(getenv('PHP_CS_FIXER_IGNORE_ENV'), \FILTER_VALIDATE_BOOL);
18✔
100
        }
101
    }
102

103
    /**
104
     * @return non-empty-string
105
     */
106
    public function getCacheFile(): string
107
    {
108
        return $this->cacheFile;
3✔
109
    }
110

111
    public function getCustomFixers(): array
112
    {
113
        return $this->customFixers;
5✔
114
    }
115

116
    public function getCustomRuleSets(): array
117
    {
118
        return array_values($this->customRuleSets);
3✔
119
    }
120

121
    /**
122
     * @return iterable<\SplFileInfo>
123
     */
124
    public function getFinder(): iterable
125
    {
126
        $this->finder ??= new Finder();
4✔
127

128
        return $this->finder;
4✔
129
    }
130

131
    public function getFormat(): string
132
    {
133
        return $this->format;
1✔
134
    }
135

136
    public function getHideProgress(): bool
137
    {
138
        return $this->hideProgress;
1✔
139
    }
140

141
    public function getIndent(): string
142
    {
143
        return $this->indent;
1✔
144
    }
145

146
    public function getLineEnding(): string
147
    {
148
        return $this->lineEnding;
1✔
149
    }
150

151
    public function getName(): string
152
    {
153
        return $this->name;
3✔
154
    }
155

156
    public function getParallelConfig(): ParallelConfig
157
    {
158
        return $this->parallelConfig;
2✔
159
    }
160

161
    public function getPhpExecutable(): ?string
162
    {
163
        return $this->phpExecutable;
1✔
164
    }
165

166
    public function getRiskyAllowed(): bool
167
    {
168
        return $this->isRiskyAllowed;
1✔
169
    }
170

171
    public function getRules(): array
172
    {
173
        return $this->rules;
2✔
174
    }
175

176
    public function getUsingCache(): bool
177
    {
178
        return $this->usingCache;
1✔
179
    }
180

181
    public function getUnsupportedPhpVersionAllowed(): bool
182
    {
183
        return $this->isUnsupportedPhpVersionAllowed;
1✔
184
    }
185

186
    public function getRuleCustomisationPolicy(): ?RuleCustomisationPolicyInterface
187
    {
188
        return $this->ruleCustomisationPolicy;
1✔
189
    }
190

191
    public function registerCustomFixers(iterable $fixers): ConfigInterface
192
    {
193
        foreach ($fixers as $fixer) {
2✔
194
            $this->addCustomFixer($fixer);
2✔
195
        }
196

197
        return $this;
2✔
198
    }
199

200
    /**
201
     * @param list<RuleSetDefinitionInterface> $ruleSets
202
     */
203
    public function registerCustomRuleSets(array $ruleSets): ConfigInterface
204
    {
205
        foreach ($ruleSets as $ruleset) {
1✔
206
            $this->customRuleSets[$ruleset->getName()] = $ruleset;
1✔
207
        }
208

209
        return $this;
1✔
210
    }
211

212
    /**
213
     * @param non-empty-string $cacheFile
214
     */
215
    public function setCacheFile(string $cacheFile): ConfigInterface
216
    {
217
        $this->cacheFile = $cacheFile;
2✔
218

219
        return $this;
2✔
220
    }
221

222
    public function setFinder(iterable $finder): ConfigInterface
223
    {
224
        $this->finder = $finder;
3✔
225

226
        return $this;
3✔
227
    }
228

229
    public function setFormat(string $format): ConfigInterface
230
    {
231
        $this->format = $format;
1✔
232

233
        return $this;
1✔
234
    }
235

236
    public function setHideProgress(bool $hideProgress): ConfigInterface
237
    {
238
        $this->hideProgress = $hideProgress;
1✔
239

240
        return $this;
1✔
241
    }
242

243
    /**
244
     * @param non-empty-string $indent
245
     */
246
    public function setIndent(string $indent): ConfigInterface
247
    {
248
        $this->indent = $indent;
1✔
249

250
        return $this;
1✔
251
    }
252

253
    /**
254
     * @param non-empty-string $lineEnding
255
     */
256
    public function setLineEnding(string $lineEnding): ConfigInterface
257
    {
258
        $this->lineEnding = $lineEnding;
1✔
259

260
        return $this;
1✔
261
    }
262

263
    public function setParallelConfig(ParallelConfig $config): ConfigInterface
264
    {
265
        $this->parallelConfig = $config;
1✔
266

267
        return $this;
1✔
268
    }
269

270
    public function setPhpExecutable(?string $phpExecutable): ConfigInterface
271
    {
272
        $this->phpExecutable = $phpExecutable;
1✔
273

274
        return $this;
1✔
275
    }
276

277
    public function setRiskyAllowed(bool $isRiskyAllowed): ConfigInterface
278
    {
279
        $this->isRiskyAllowed = $isRiskyAllowed;
×
280

281
        return $this;
×
282
    }
283

284
    public function setRules(array $rules): ConfigInterface
285
    {
286
        $this->rules = $rules;
×
287

288
        return $this;
×
289
    }
290

291
    public function setUsingCache(bool $usingCache): ConfigInterface
292
    {
293
        $this->usingCache = $usingCache;
1✔
294

295
        return $this;
1✔
296
    }
297

298
    public function setUnsupportedPhpVersionAllowed(bool $isUnsupportedPhpVersionAllowed): ConfigInterface
299
    {
300
        $this->isUnsupportedPhpVersionAllowed = $isUnsupportedPhpVersionAllowed;
1✔
301

302
        return $this;
1✔
303
    }
304

305
    public function setRuleCustomisationPolicy(?RuleCustomisationPolicyInterface $ruleCustomisationPolicy): ConfigInterface
306
    {
307
        // explicitly prevent policy with no proper version defined
308
        if (null !== $ruleCustomisationPolicy && '' === $ruleCustomisationPolicy->getPolicyVersionForCache()) {
1✔
309
            throw new \InvalidArgumentException('The Rule Customisation Policy version cannot be an empty string.');
×
310
        }
311

312
        $this->ruleCustomisationPolicy = $ruleCustomisationPolicy;
1✔
313

314
        return $this;
1✔
315
    }
316

317
    private function addCustomFixer(FixerInterface $fixer): void
318
    {
319
        $this->customFixers[] = $fixer;
2✔
320
    }
321
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc