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

keradus / PHP-CS-Fixer / 24023612215

06 Apr 2026 07:44AM UTC coverage: 92.938% (+0.01%) from 92.928%
24023612215

push

github

keradus
refactor: ConfigurableFixerTemplateFixer - move handling example file from fixing logic to definition

2 of 3 new or added lines in 1 file covered. (66.67%)

261 existing lines in 11 files now uncovered.

29268 of 31492 relevant lines covered (92.94%)

43.97 hits per line

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

91.67
/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

96
        // @TODO 4.0 cleanup
97
        if (Future::isFutureModeEnabled() || filter_var(getenv('PHP_CS_FIXER_PARALLEL'), \FILTER_VALIDATE_BOOL)) {
18✔
98
            $this->parallelConfig = ParallelConfigFactory::detect();
1✔
99
        } else {
100
            $this->parallelConfig = ParallelConfigFactory::sequential();
17✔
101
        }
102

103
        // @TODO 4.0 cleanup
104
        if (false !== getenv('PHP_CS_FIXER_IGNORE_ENV')) {
18✔
105
            $this->isUnsupportedPhpVersionAllowed = filter_var(getenv('PHP_CS_FIXER_IGNORE_ENV'), \FILTER_VALIDATE_BOOL);
18✔
106
        }
107
    }
108

109
    /**
110
     * @return non-empty-string
111
     */
112
    public function getCacheFile(): string
113
    {
114
        return $this->cacheFile;
3✔
115
    }
116

117
    public function getCustomFixers(): array
118
    {
119
        return $this->customFixers;
5✔
120
    }
121

122
    public function getCustomRuleSets(): array
123
    {
124
        return array_values($this->customRuleSets);
3✔
125
    }
126

127
    /**
128
     * @return iterable<\SplFileInfo>
129
     */
130
    public function getFinder(): iterable
131
    {
132
        $this->finder ??= new Finder();
4✔
133

134
        return $this->finder;
4✔
135
    }
136

137
    public function getFormat(): string
138
    {
139
        return $this->format;
1✔
140
    }
141

142
    public function getHideProgress(): bool
143
    {
144
        return $this->hideProgress;
1✔
145
    }
146

147
    public function getIndent(): string
148
    {
149
        return $this->indent;
1✔
150
    }
151

152
    public function getLineEnding(): string
153
    {
154
        return $this->lineEnding;
1✔
155
    }
156

157
    public function getName(): string
158
    {
159
        return $this->name;
3✔
160
    }
161

162
    public function getParallelConfig(): ParallelConfig
163
    {
164
        return $this->parallelConfig;
2✔
165
    }
166

167
    public function getPhpExecutable(): ?string
168
    {
169
        return $this->phpExecutable;
1✔
170
    }
171

172
    public function getRiskyAllowed(): bool
173
    {
174
        return $this->isRiskyAllowed;
1✔
175
    }
176

177
    public function getRules(): array
178
    {
179
        return $this->rules;
2✔
180
    }
181

182
    public function getUsingCache(): bool
183
    {
184
        return $this->usingCache;
1✔
185
    }
186

187
    public function getUnsupportedPhpVersionAllowed(): bool
188
    {
189
        return $this->isUnsupportedPhpVersionAllowed;
1✔
190
    }
191

192
    public function getRuleCustomisationPolicy(): ?RuleCustomisationPolicyInterface
193
    {
194
        return $this->ruleCustomisationPolicy;
1✔
195
    }
196

197
    public function registerCustomFixers(iterable $fixers): ConfigInterface
198
    {
199
        foreach ($fixers as $fixer) {
2✔
200
            $this->addCustomFixer($fixer);
2✔
201
        }
202

203
        return $this;
2✔
204
    }
205

206
    /**
207
     * @param list<RuleSetDefinitionInterface> $ruleSets
208
     */
209
    public function registerCustomRuleSets(array $ruleSets): ConfigInterface
210
    {
211
        foreach ($ruleSets as $ruleset) {
1✔
212
            $this->customRuleSets[$ruleset->getName()] = $ruleset;
1✔
213
        }
214

215
        return $this;
1✔
216
    }
217

218
    /**
219
     * @param non-empty-string $cacheFile
220
     */
221
    public function setCacheFile(string $cacheFile): ConfigInterface
222
    {
223
        $this->cacheFile = $cacheFile;
2✔
224

225
        return $this;
2✔
226
    }
227

228
    public function setFinder(iterable $finder): ConfigInterface
229
    {
230
        $this->finder = $finder;
3✔
231

232
        return $this;
3✔
233
    }
234

235
    public function setFormat(string $format): ConfigInterface
236
    {
237
        $this->format = $format;
1✔
238

239
        return $this;
1✔
240
    }
241

242
    public function setHideProgress(bool $hideProgress): ConfigInterface
243
    {
244
        $this->hideProgress = $hideProgress;
1✔
245

246
        return $this;
1✔
247
    }
248

249
    /**
250
     * @param non-empty-string $indent
251
     */
252
    public function setIndent(string $indent): ConfigInterface
253
    {
254
        $this->indent = $indent;
1✔
255

256
        return $this;
1✔
257
    }
258

259
    /**
260
     * @param non-empty-string $lineEnding
261
     */
262
    public function setLineEnding(string $lineEnding): ConfigInterface
263
    {
264
        $this->lineEnding = $lineEnding;
1✔
265

266
        return $this;
1✔
267
    }
268

269
    public function setParallelConfig(ParallelConfig $config): ConfigInterface
270
    {
271
        $this->parallelConfig = $config;
1✔
272

273
        return $this;
1✔
274
    }
275

276
    public function setPhpExecutable(?string $phpExecutable): ConfigInterface
277
    {
278
        $this->phpExecutable = $phpExecutable;
1✔
279

280
        return $this;
1✔
281
    }
282

283
    public function setRiskyAllowed(bool $isRiskyAllowed): ConfigInterface
284
    {
UNCOV
285
        $this->isRiskyAllowed = $isRiskyAllowed;
×
286

UNCOV
287
        return $this;
×
288
    }
289

290
    public function setRules(array $rules): ConfigInterface
291
    {
UNCOV
292
        $this->rules = $rules;
×
293

UNCOV
294
        return $this;
×
295
    }
296

297
    public function setUsingCache(bool $usingCache): ConfigInterface
298
    {
299
        $this->usingCache = $usingCache;
1✔
300

301
        return $this;
1✔
302
    }
303

304
    public function setUnsupportedPhpVersionAllowed(bool $isUnsupportedPhpVersionAllowed): ConfigInterface
305
    {
306
        $this->isUnsupportedPhpVersionAllowed = $isUnsupportedPhpVersionAllowed;
1✔
307

308
        return $this;
1✔
309
    }
310

311
    public function setRuleCustomisationPolicy(?RuleCustomisationPolicyInterface $ruleCustomisationPolicy): ConfigInterface
312
    {
313
        // explicitly prevent policy with no proper version defined
314
        if (null !== $ruleCustomisationPolicy && '' === $ruleCustomisationPolicy->getPolicyVersionForCache()) {
1✔
UNCOV
315
            throw new \InvalidArgumentException('The Rule Customisation Policy version cannot be an empty string.');
×
316
        }
317

318
        $this->ruleCustomisationPolicy = $ruleCustomisationPolicy;
1✔
319

320
        return $this;
1✔
321
    }
322

323
    private function addCustomFixer(FixerInterface $fixer): void
324
    {
325
        $this->customFixers[] = $fixer;
2✔
326
    }
327
}
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