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

keradus / PHP-CS-Fixer / 17252691116

26 Aug 2025 11:09PM UTC coverage: 94.743% (-0.01%) from 94.755%
17252691116

push

github

keradus
chore: apply phpdoc_tag_no_named_arguments

28313 of 29884 relevant lines covered (94.74%)

45.64 hits per line

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

97.5
/src/Fixer/Phpdoc/PhpdocAnnotationWithoutDotFixer.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\DocBlock\DocBlock;
19
use PhpCsFixer\FixerDefinition\CodeSample;
20
use PhpCsFixer\FixerDefinition\FixerDefinition;
21
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
22
use PhpCsFixer\Preg;
23
use PhpCsFixer\Tokenizer\Token;
24
use PhpCsFixer\Tokenizer\Tokens;
25

26
/**
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
final class PhpdocAnnotationWithoutDotFixer extends AbstractFixer
32
{
33
    /**
34
     * @var non-empty-list<string>
35
     */
36
    private array $tags = ['throws', 'return', 'param', 'internal', 'deprecated', 'var', 'type'];
37

38
    public function getDefinition(): FixerDefinitionInterface
39
    {
40
        return new FixerDefinition(
3✔
41
            'PHPDoc annotation descriptions should not be a sentence.',
3✔
42
            [new CodeSample('<?php
3✔
43
/**
44
 * @param string $bar Some string.
45
 */
46
function foo ($bar) {}
47
')]
3✔
48
        );
3✔
49
    }
50

51
    /**
52
     * {@inheritdoc}
53
     *
54
     * Must run before PhpdocAlignFixer.
55
     * Must run after AlignMultilineCommentFixer, CommentToPhpdocFixer, PhpdocIndentFixer, PhpdocToCommentFixer.
56
     */
57
    public function getPriority(): int
58
    {
59
        return 17;
1✔
60
    }
61

62
    public function isCandidate(Tokens $tokens): bool
63
    {
64
        return $tokens->isTokenKindFound(\T_DOC_COMMENT);
13✔
65
    }
66

67
    protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
68
    {
69
        foreach ($tokens as $index => $token) {
13✔
70
            if (!$token->isGivenKind(\T_DOC_COMMENT)) {
13✔
71
                continue;
13✔
72
            }
73

74
            $doc = new DocBlock($token->getContent());
13✔
75
            $annotations = $doc->getAnnotations();
13✔
76

77
            if (0 === \count($annotations)) {
13✔
78
                continue;
×
79
            }
80

81
            foreach ($annotations as $annotation) {
13✔
82
                if (
83
                    !$annotation->getTag()->valid() || !\in_array($annotation->getTag()->getName(), $this->tags, true)
13✔
84
                ) {
85
                    continue;
1✔
86
                }
87

88
                $lineAfterAnnotation = $doc->getLine($annotation->getEnd() + 1);
13✔
89
                if (null !== $lineAfterAnnotation) {
13✔
90
                    $lineAfterAnnotationTrimmed = ltrim($lineAfterAnnotation->getContent());
13✔
91
                    if ('' === $lineAfterAnnotationTrimmed || !str_starts_with($lineAfterAnnotationTrimmed, '*')) {
13✔
92
                        // malformed PHPDoc, missing asterisk !
93
                        continue;
1✔
94
                    }
95
                }
96

97
                $content = $annotation->getContent();
12✔
98

99
                if (
100
                    !Preg::match('/[.。]\h*$/u', $content)
12✔
101
                    || Preg::match('/[.。](?!\h*$)/u', $content, $matches)
12✔
102
                ) {
103
                    continue;
11✔
104
                }
105

106
                $endLine = $doc->getLine($annotation->getEnd());
8✔
107
                $endLine->setContent(Preg::replace('/(?<![.。])[.。]\h*(\H+)$/u', '\1', $endLine->getContent()));
8✔
108

109
                $startLine = $doc->getLine($annotation->getStart());
8✔
110
                $optionalTypeRegEx = $annotation->supportTypes()
8✔
111
                    ? \sprintf('(?:%s\s+(?:\$\w+\s+)?)?', preg_quote(implode('|', $annotation->getTypes()), '/'))
7✔
112
                    : '';
1✔
113
                $content = Preg::replaceCallback(
8✔
114
                    '/^(\s*\*\s*@\w+\s+'.$optionalTypeRegEx.')(\p{Lu}?(?=\p{Ll}|\p{Zs}))(.*)$/',
8✔
115
                    static fn (array $matches): string => $matches[1].mb_strtolower($matches[2]).$matches[3],
8✔
116
                    $startLine->getContent(),
8✔
117
                    1
8✔
118
                );
8✔
119
                $startLine->setContent($content);
8✔
120
            }
121

122
            $tokens[$index] = new Token([\T_DOC_COMMENT, $doc->getContent()]);
13✔
123
        }
124
    }
125
}
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