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

keradus / PHP-CS-Fixer / 17678835382

12 Sep 2025 03:24PM UTC coverage: 94.69% (-0.06%) from 94.75%
17678835382

push

github

keradus
fix typo

1 of 1 new or added line in 1 file covered. (100.0%)

1042 existing lines in 177 files now uncovered.

28424 of 30018 relevant lines covered (94.69%)

45.5 hits per line

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

97.33
/src/Documentation/RuleSetDocumentationGenerator.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\Documentation;
16

17
use PhpCsFixer\Fixer\FixerInterface;
18
use PhpCsFixer\Preg;
19
use PhpCsFixer\RuleSet\DeprecatedRuleSetDescriptionInterface;
20
use PhpCsFixer\RuleSet\RuleSetDescriptionInterface;
21
use PhpCsFixer\Utils;
22

23
/**
24
 * @readonly
25
 *
26
 * @internal
27
 *
28
 * @no-named-arguments Parameter names are not covered by the backward compatibility promise.
29
 */
30
final class RuleSetDocumentationGenerator
31
{
32
    private DocumentationLocator $locator;
33

34
    public function __construct(DocumentationLocator $locator)
35
    {
36
        $this->locator = $locator;
3✔
37
    }
38

39
    /**
40
     * @param list<FixerInterface> $fixers
41
     */
42
    public function generateRuleSetsDocumentation(RuleSetDescriptionInterface $definition, array $fixers): string
43
    {
44
        $fixerNames = [];
2✔
45

46
        foreach ($fixers as $fixer) {
2✔
47
            $fixerNames[$fixer->getName()] = $fixer;
2✔
48
        }
49

50
        $title = "Rule set ``{$definition->getName()}``";
2✔
51
        $titleLine = str_repeat('=', \strlen($title));
2✔
52
        $doc = "{$titleLine}\n{$title}\n{$titleLine}\n\n".$definition->getDescription();
2✔
53

54
        $warnings = [];
2✔
55
        if ($definition instanceof DeprecatedRuleSetDescriptionInterface) {
2✔
56
            $deprecationDescription = <<<'RST'
1✔
57

58
                This rule set is deprecated and will be removed in the next major version
59
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
60
                RST;
1✔
61
            $alternatives = $definition->getSuccessorsNames();
1✔
62

63
            if (0 !== \count($alternatives)) {
1✔
64
                $deprecationDescription .= RstUtils::toRst(
1✔
65
                    \sprintf(
1✔
66
                        "\n\nYou should use %s instead.",
1✔
67
                        Utils::naturalLanguageJoinWithBackticks($alternatives)
1✔
68
                    ),
1✔
69
                    0
1✔
70
                );
1✔
71
            } else {
UNCOV
72
                $deprecationDescription .= 'No replacement available.';
×
73
            }
74

75
            $warnings[] = $deprecationDescription;
1✔
76
        }
77

78
        if ($definition->isRisky()) {
2✔
79
            $warnings[] = <<<'RST'
1✔
80

81
                This set contains rules that are risky
82
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
83

84
                Using this rule set may lead to changes in your code's logic and behaviour. Use it with caution and review changes before incorporating them into your code base.
85
                RST;
1✔
86
        }
87

88
        if ([] !== $warnings) {
2✔
89
            $warningsHeader = 1 === \count($warnings) ? 'Warning' : 'Warnings';
2✔
90

91
            $warningsHeaderLine = str_repeat('-', \strlen($warningsHeader));
2✔
92
            $doc .= "\n\n".implode(
2✔
93
                "\n",
2✔
94
                [
2✔
95
                    $warningsHeader,
2✔
96
                    $warningsHeaderLine,
2✔
97
                    ...$warnings,
2✔
98
                ]
2✔
99
            );
2✔
100
        }
101

102
        $rules = $definition->getRules();
2✔
103

104
        if ([] === $rules) {
2✔
UNCOV
105
            $doc .= "\n\nThis is an empty set.";
×
106
        } else {
107
            $enabledRules = array_filter($rules, static fn ($config) => false !== $config);
2✔
108
            $disabledRules = array_filter($rules, static fn ($config) => false === $config);
2✔
109

110
            $listRules = function (array $rules) use (&$doc, $fixerNames): void {
2✔
111
                foreach ($rules as $rule => $config) {
2✔
112
                    if (str_starts_with($rule, '@')) {
2✔
113
                        $ruleSetPath = $this->locator->getRuleSetsDocumentationFilePath($rule);
2✔
114
                        $ruleSetPath = substr($ruleSetPath, strrpos($ruleSetPath, '/'));
2✔
115

116
                        $doc .= "\n- `{$rule} <.{$ruleSetPath}>`_";
2✔
117
                    } else {
118
                        $path = Preg::replace(
1✔
119
                            '#^'.preg_quote($this->locator->getFixersDocumentationDirectoryPath(), '#').'/#',
1✔
120
                            './../rules/',
1✔
121
                            $this->locator->getFixerDocumentationFilePath($fixerNames[$rule])
1✔
122
                        );
1✔
123

124
                        $doc .= "\n- `{$rule} <{$path}>`_";
1✔
125
                    }
126

127
                    if (!\is_bool($config)) {
2✔
128
                        $doc .= " with config:\n\n  ``".Utils::toString($config)."``\n";
1✔
129
                    }
130
                }
131
            };
2✔
132

133
            if ([] !== $enabledRules) {
2✔
134
                $doc .= "\n\nRules\n-----\n";
2✔
135
                $listRules($enabledRules);
2✔
136
            }
137

138
            if ([] !== $disabledRules) {
2✔
139
                $doc .= "\n\nDisabled rules\n--------------\n";
1✔
140
                $listRules($disabledRules);
1✔
141
            }
142
        }
143

144
        return $doc."\n";
2✔
145
    }
146

147
    /**
148
     * @param array<string, RuleSetDescriptionInterface> $setDefinitions
149
     */
150
    public function generateRuleSetsDocumentationIndex(array $setDefinitions): string
151
    {
152
        $documentation = <<<'RST'
1✔
153
            ===========================
154
            List of Available Rule sets
155
            ===========================
156
            RST;
1✔
157

158
        foreach ($setDefinitions as $path => $definition) {
1✔
159
            $path = substr($path, strrpos($path, '/'));
1✔
160

161
            $attributes = [];
1✔
162

163
            if ($definition instanceof DeprecatedRuleSetDescriptionInterface) {
1✔
164
                $attributes[] = 'deprecated';
1✔
165
            }
166

167
            $attributes = 0 === \count($attributes)
1✔
168
                ? ''
1✔
169
                : ' *('.implode(', ', $attributes).')*';
1✔
170

171
            $documentation .= "\n- `{$definition->getName()} <.{$path}>`_{$attributes}";
1✔
172
        }
173

174
        return $documentation."\n";
1✔
175
    }
176
}
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