• 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.44
/src/Fixer/Phpdoc/PhpdocInlineTagNormalizerFixer.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\Fixer\Phpdoc;
16

17
use PhpCsFixer\AbstractFixer;
18
use PhpCsFixer\Fixer\ConfigurableFixerInterface;
19
use PhpCsFixer\Fixer\ConfigurableFixerTrait;
20
use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
21
use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverInterface;
22
use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
23
use PhpCsFixer\FixerDefinition\CodeSample;
24
use PhpCsFixer\FixerDefinition\FixerDefinition;
25
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
26
use PhpCsFixer\Preg;
27
use PhpCsFixer\Tokenizer\Token;
28
use PhpCsFixer\Tokenizer\Tokens;
29

30
/**
31
 * @phpstan-type _AutogeneratedInputConfiguration array{
32
 *  tags?: list<string>,
33
 * }
34
 * @phpstan-type _AutogeneratedComputedConfiguration array{
35
 *  tags: list<string>,
36
 * }
37
 *
38
 * @implements ConfigurableFixerInterface<_AutogeneratedInputConfiguration, _AutogeneratedComputedConfiguration>
39
 *
40
 * @no-named-arguments Parameter names are not covered by the backward compatibility promise.
41
 */
42
final class PhpdocInlineTagNormalizerFixer extends AbstractFixer implements ConfigurableFixerInterface
43
{
44
    /** @use ConfigurableFixerTrait<_AutogeneratedInputConfiguration, _AutogeneratedComputedConfiguration> */
45
    use ConfigurableFixerTrait;
46

47
    public function isCandidate(Tokens $tokens): bool
48
    {
49
        return $tokens->isTokenKindFound(\T_DOC_COMMENT);
80✔
50
    }
51

52
    public function getDefinition(): FixerDefinitionInterface
53
    {
54
        return new FixerDefinition(
3✔
55
            'Fixes PHPDoc inline tags.',
3✔
56
            [
3✔
57
                new CodeSample(
3✔
58
                    "<?php\n/**\n * @{TUTORIAL}\n * {{ @link }}\n * @inheritDoc\n */\n"
3✔
59
                ),
3✔
60
                new CodeSample(
3✔
61
                    "<?php\n/**\n * @{TUTORIAL}\n * {{ @link }}\n * @inheritDoc\n */\n",
3✔
62
                    ['tags' => ['TUTORIAL']]
3✔
63
                ),
3✔
64
            ]
3✔
65
        );
3✔
66
    }
67

68
    /**
69
     * {@inheritdoc}
70
     *
71
     * Must run before PhpdocAlignFixer.
72
     * Must run after AlignMultilineCommentFixer, CommentToPhpdocFixer, PhpdocIndentFixer, PhpdocScalarFixer, PhpdocToCommentFixer, PhpdocTypesFixer.
73
     */
74
    public function getPriority(): int
75
    {
76
        return 0;
1✔
77
    }
78

79
    protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
80
    {
81
        if (0 === \count($this->configuration['tags'])) {
80✔
UNCOV
82
            return;
×
83
        }
84

85
        foreach ($tokens as $index => $token) {
80✔
86
            if (!$token->isGivenKind(\T_DOC_COMMENT)) {
80✔
87
                continue;
80✔
88
            }
89

90
            // Move `@` inside tag, for example @{tag} -> {@tag}, replace multiple curly brackets,
91
            // remove spaces between '{' and '@', remove white space between end
92
            // of text and closing bracket and between the tag and inline comment.
93
            $content = Preg::replaceCallback(
80✔
94
                \sprintf(
80✔
95
                    '#(?:@{+|{+\h*@)\h*(%s)\b([^}]*)(?:}+)#i',
80✔
96
                    implode('|', array_map(static fn (string $tag): string => preg_quote($tag, '/'), $this->configuration['tags']))
80✔
97
                ),
80✔
98
                static function (array $matches): string {
80✔
99
                    $doc = trim($matches[2]);
68✔
100

101
                    if ('' === $doc) {
68✔
102
                        return '{@'.$matches[1].'}';
35✔
103
                    }
104

105
                    return '{@'.$matches[1].' '.$doc.'}';
33✔
106
                },
80✔
107
                $token->getContent()
80✔
108
            );
80✔
109

110
            $tokens[$index] = new Token([\T_DOC_COMMENT, $content]);
80✔
111
        }
112
    }
113

114
    protected function createConfigurationDefinition(): FixerConfigurationResolverInterface
115
    {
116
        return new FixerConfigurationResolver([
89✔
117
            (new FixerOptionBuilder('tags', 'The list of tags to normalize.'))
89✔
118
                ->setAllowedTypes(['string[]'])
89✔
119
                ->setDefault(['example', 'id', 'internal', 'inheritdoc', 'inheritdocs', 'link', 'source', 'toc', 'tutorial'])
89✔
120
                ->getOption(),
89✔
121
        ]);
89✔
122
    }
123
}
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