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

keradus / PHP-CS-Fixer / 17194174105

24 Aug 2025 09:46PM UTC coverage: 94.742% (-0.01%) from 94.752%
17194174105

push

github

keradus
Merge branch '__sets_update' of github.com:keradus/PHP-CS-Fixer into __sets_update

8 of 9 new or added lines in 4 files covered. (88.89%)

7 existing lines in 3 files now uncovered.

28307 of 29878 relevant lines covered (94.74%)

45.65 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
    public function isCandidate(Tokens $tokens): bool
33
    {
34
        return $tokens->isTokenKindFound(\T_DOC_COMMENT);
48✔
35
    }
36

37
    protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
38
    {
39
        foreach ($tokens as $index => $token) {
47✔
40
            if (!$token->isGivenKind(\T_DOC_COMMENT)) {
47✔
41
                continue;
47✔
42
            }
43

44
            $doc = new DocBlock($token->getContent());
47✔
45
            $annotations = $doc->getAnnotationsOfType(Annotation::TAGS_WITH_TYPES);
47✔
46

47
            if (0 === \count($annotations)) {
47✔
48
                continue;
3✔
49
            }
50

51
            foreach ($annotations as $annotation) {
44✔
52
                $this->fixType($annotation);
44✔
53
            }
54

55
            $tokens[$index] = new Token([\T_DOC_COMMENT, $doc->getContent()]);
44✔
56
        }
57
    }
58

59
    /**
60
     * Actually normalize the given type.
61
     */
62
    abstract protected function normalize(string $type): string;
63

64
    /**
65
     * Fix the type at the given line.
66
     *
67
     * We must be super careful not to modify parts of words.
68
     *
69
     * This will be nicely handled behind the scenes for us by the annotation class.
70
     */
71
    private function fixType(Annotation $annotation): void
72
    {
73
        $typeExpression = $annotation->getTypeExpression();
44✔
74

75
        if (null === $typeExpression) {
44✔
UNCOV
76
            return;
×
77
        }
78

79
        $newTypeExpression = $typeExpression->mapTypes(function (TypeExpression $type) {
44✔
80
            if (!$type->isCompositeType()) {
44✔
81
                $value = $this->normalize($type->toString());
44✔
82

83
                return new TypeExpression($value, null, []);
44✔
84
            }
85

86
            return $type;
15✔
87
        });
44✔
88

89
        $annotation->setTypes([$newTypeExpression->toString()]);
44✔
90
    }
91
}
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