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

keradus / PHP-CS-Fixer / 17194063523

24 Aug 2025 09:34PM UTC coverage: 94.745% (-0.01%) from 94.756%
17194063523

push

github

keradus
update allow_hidden_params - unify towards future default

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

8 existing lines in 3 files now uncovered.

28325 of 29896 relevant lines covered (94.75%)

45.83 hits per line

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

95.24
/src/AbstractPhpdocTypesFixer.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\DocBlock\Annotation;
18
use PhpCsFixer\DocBlock\DocBlock;
19
use PhpCsFixer\DocBlock\TypeExpression;
20
use PhpCsFixer\Tokenizer\Token;
21
use PhpCsFixer\Tokenizer\Tokens;
22

23
/**
24
 * This abstract fixer provides a base for fixers to fix types in PHPDoc.
25
 *
26
 * @author Graham Campbell <hello@gjcampbell.co.uk>
27
 *
28
 * @internal
29
 */
30
abstract class AbstractPhpdocTypesFixer extends AbstractFixer
31
{
32
    /**
33
     * The annotation tags search inside.
34
     *
35
     * @var list<string>
36
     */
37
    protected array $tags = Annotation::TAGS_WITH_TYPES;
38

39
    public function isCandidate(Tokens $tokens): bool
40
    {
41
        return $tokens->isTokenKindFound(\T_DOC_COMMENT);
48✔
42
    }
43

44
    protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
45
    {
46
        foreach ($tokens as $index => $token) {
47✔
47
            if (!$token->isGivenKind(\T_DOC_COMMENT)) {
47✔
48
                continue;
47✔
49
            }
50

51
            $doc = new DocBlock($token->getContent());
47✔
52
            $annotations = $doc->getAnnotationsOfType($this->tags);
47✔
53

54
            if (0 === \count($annotations)) {
47✔
55
                continue;
3✔
56
            }
57

58
            foreach ($annotations as $annotation) {
44✔
59
                $this->fixType($annotation);
44✔
60
            }
61

62
            $tokens[$index] = new Token([\T_DOC_COMMENT, $doc->getContent()]);
44✔
63
        }
64
    }
65

66
    /**
67
     * Actually normalize the given type.
68
     */
69
    abstract protected function normalize(string $type): string;
70

71
    /**
72
     * Fix the type at the given line.
73
     *
74
     * We must be super careful not to modify parts of words.
75
     *
76
     * This will be nicely handled behind the scenes for us by the annotation class.
77
     */
78
    private function fixType(Annotation $annotation): void
79
    {
80
        $typeExpression = $annotation->getTypeExpression();
44✔
81

82
        if (null === $typeExpression) {
44✔
UNCOV
83
            return;
×
84
        }
85

86
        $newTypeExpression = $typeExpression->mapTypes(function (TypeExpression $type) {
44✔
87
            if (!$type->isCompositeType()) {
44✔
88
                $value = $this->normalize($type->toString());
44✔
89

90
                return new TypeExpression($value, null, []);
44✔
91
            }
92

93
            return $type;
15✔
94
        });
44✔
95

96
        $annotation->setTypes([$newTypeExpression->toString()]);
44✔
97
    }
98
}
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