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

keradus / PHP-CS-Fixer / 18051010410

26 Sep 2025 10:40PM UTC coverage: 94.308% (-0.02%) from 94.331%
18051010410

push

github

web-flow
chore: use accidentally missing `@auto:risky` (#9102)

28583 of 30308 relevant lines covered (94.31%)

45.24 hits per line

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

66.67
/src/RuleSet/RuleSets.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\RuleSet;
16

17
use PhpCsFixer\RuleSetNameValidator;
18
use Symfony\Component\Finder\Finder;
19

20
/**
21
 * Set of rule sets to be used by fixer.
22
 *
23
 * @internal
24
 *
25
 * @no-named-arguments Parameter names are not covered by the backward compatibility promise.
26
 */
27
final class RuleSets
28
{
29
    /**
30
     * @var null|array<string, RuleSetDefinitionInterface>
31
     */
32
    private static ?array $builtInSetDefinitions = null;
33

34
    /**
35
     * @var array<string, RuleSetDefinitionInterface>
36
     */
37
    private static array $customRuleSetDefinitions = [];
38

39
    /**
40
     * @return array<string, RuleSetDefinitionInterface>
41
     */
42
    public static function getSetDefinitions(): array
43
    {
44
        $allRuleSets = array_merge(
118✔
45
            self::getBuiltInSetDefinitions(),
118✔
46
            self::$customRuleSetDefinitions
118✔
47
        );
118✔
48

49
        uksort($allRuleSets, static fn (string $x, string $y): int => strnatcmp($x, $y));
118✔
50

51
        return $allRuleSets;
118✔
52
    }
53

54
    /**
55
     * @return array<string, RuleSetDefinitionInterface>
56
     */
57
    public static function getBuiltInSetDefinitions(): array
58
    {
59
        if (null === self::$builtInSetDefinitions) {
118✔
60
            self::$builtInSetDefinitions = [];
×
61

62
            foreach (Finder::create()->files()->in(__DIR__.'/Sets') as $file) {
×
63
                /** @var class-string<RuleSetDefinitionInterface> $class */
64
                $class = 'PhpCsFixer\RuleSet\Sets\\'.$file->getBasename('.php');
×
65

66
                /** @var RuleSetDefinitionInterface */
67
                $set = new $class();
×
68

69
                if (!RuleSetNameValidator::isValid($set->getName(), false)) {
×
70
                    throw new \InvalidArgumentException(\sprintf('Rule set name invalid: %s', $set->getName()));
×
71
                }
72

73
                self::$builtInSetDefinitions[$set->getName()] = $set;
×
74
            }
75

76
            uksort(self::$builtInSetDefinitions, static fn (string $x, string $y): int => strnatcmp($x, $y));
×
77
        }
78

79
        return self::$builtInSetDefinitions;
118✔
80
    }
81

82
    /**
83
     * @return list<string>
84
     */
85
    public static function getSetDefinitionNames(): array
86
    {
87
        return array_keys(self::getSetDefinitions());
1✔
88
    }
89

90
    public static function getSetDefinition(string $name): RuleSetDefinitionInterface
91
    {
92
        $definitions = self::getSetDefinitions();
19✔
93

94
        if (!isset($definitions[$name])) {
19✔
95
            throw new \InvalidArgumentException(\sprintf('Set "%s" does not exist.', $name));
1✔
96
        }
97

98
        return $definitions[$name];
18✔
99
    }
100

101
    public static function registerCustomRuleSet(RuleSetDefinitionInterface $ruleset): void
102
    {
103
        $name = $ruleset->getName();
2✔
104

105
        if (!RuleSetNameValidator::isValid($name, true)) {
2✔
106
            throw new \InvalidArgumentException('RuleSet name must begin with "@" and a letter (a-z, A-Z), and can contain only letters (a-z, A-Z), numbers, underscores, slashes, colons, dots and hyphens.');
×
107
        }
108

109
        if (\array_key_exists($name, self::getSetDefinitions())) {
2✔
110
            throw new \InvalidArgumentException(\sprintf('Set "%s" is already defined.', $name));
1✔
111
        }
112

113
        self::$customRuleSetDefinitions[$name] = $ruleset;
2✔
114
    }
115
}
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