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

keradus / PHP-CS-Fixer / 17193291398

24 Aug 2025 08:15PM UTC coverage: 94.745% (+0.005%) from 94.74%
17193291398

push

github

web-flow
chore: deprecate `Annotation::getTagsWithTypes` in favor of `TAGS_WITH_TYPES` constant (#8977)

4 of 4 new or added lines in 3 files covered. (100.0%)

108 existing lines in 8 files now uncovered.

28322 of 29893 relevant lines covered (94.74%)

45.84 hits per line

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

9.38
/src/Fixer/AbstractPhpUnitFixer.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;
16

17
use PhpCsFixer\AbstractFixer;
18
use PhpCsFixer\Tokenizer\Analyzer\Analysis\NamespaceUseAnalysis;
19
use PhpCsFixer\Tokenizer\Analyzer\AttributeAnalyzer;
20
use PhpCsFixer\Tokenizer\Analyzer\FullyQualifiedNameAnalyzer;
21
use PhpCsFixer\Tokenizer\Analyzer\FunctionsAnalyzer;
22
use PhpCsFixer\Tokenizer\Analyzer\PhpUnitTestCaseAnalyzer;
23
use PhpCsFixer\Tokenizer\FCT;
24
use PhpCsFixer\Tokenizer\Tokens;
25

26
/**
27
 * @internal
28
 */
29
abstract class AbstractPhpUnitFixer extends AbstractFixer
30
{
31
    use DocBlockAnnotationTrait;
32

33
    public function isCandidate(Tokens $tokens): bool
34
    {
35
        return $tokens->isAllTokenKindsFound([\T_CLASS, \T_STRING]);
60✔
36
    }
37

38
    final protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
39
    {
40
        foreach ((new PhpUnitTestCaseAnalyzer())->findPhpUnitClasses($tokens) as $indices) {
60✔
41
            $this->applyPhpUnitClassFix($tokens, $indices[0], $indices[1]);
57✔
42
        }
43
    }
44

45
    abstract protected function applyPhpUnitClassFix(Tokens $tokens, int $startIndex, int $endIndex): void;
46

47
    /**
48
     * @return iterable<array{
49
     *     index: int,
50
     *     loweredName: string,
51
     *     openBraceIndex: int,
52
     *     closeBraceIndex: int,
53
     * }>
54
     */
55
    protected function getPreviousAssertCall(Tokens $tokens, int $startIndex, int $endIndex): iterable
56
    {
UNCOV
57
        $functionsAnalyzer = new FunctionsAnalyzer();
×
58

UNCOV
59
        for ($index = $endIndex; $index > $startIndex; --$index) {
×
UNCOV
60
            $index = $tokens->getPrevTokenOfKind($index, [[\T_STRING]]);
×
61

UNCOV
62
            if (null === $index) {
×
UNCOV
63
                return;
×
64
            }
65

66
            // test if "assert" something call
UNCOV
67
            $loweredContent = strtolower($tokens[$index]->getContent());
×
68

UNCOV
69
            if (!str_starts_with($loweredContent, 'assert')) {
×
UNCOV
70
                continue;
×
71
            }
72

73
            // test candidate for simple calls like: ([\]+'some fixable call'(...))
UNCOV
74
            $openBraceIndex = $tokens->getNextMeaningfulToken($index);
×
75

UNCOV
76
            if (!$tokens[$openBraceIndex]->equals('(')) {
×
UNCOV
77
                continue;
×
78
            }
79

UNCOV
80
            if (!$functionsAnalyzer->isTheSameClassCall($tokens, $index)) {
×
UNCOV
81
                continue;
×
82
            }
83

UNCOV
84
            yield [
×
UNCOV
85
                'index' => $index,
×
UNCOV
86
                'loweredName' => $loweredContent,
×
UNCOV
87
                'openBraceIndex' => $openBraceIndex,
×
UNCOV
88
                'closeBraceIndex' => $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openBraceIndex),
×
UNCOV
89
            ];
×
90
        }
91
    }
92

93
    final protected function isTestAttributePresent(Tokens $tokens, int $index): bool
94
    {
UNCOV
95
        $attributeIndex = $tokens->getPrevTokenOfKind($index, ['{', [FCT::T_ATTRIBUTE]]);
×
UNCOV
96
        if (!$tokens[$attributeIndex]->isGivenKind(FCT::T_ATTRIBUTE)) {
×
UNCOV
97
            return false;
×
98
        }
99

UNCOV
100
        $fullyQualifiedNameAnalyzer = new FullyQualifiedNameAnalyzer($tokens);
×
101

UNCOV
102
        foreach (AttributeAnalyzer::collect($tokens, $attributeIndex) as $attributeAnalysis) {
×
UNCOV
103
            foreach ($attributeAnalysis->getAttributes() as $attribute) {
×
UNCOV
104
                $attributeName = strtolower($fullyQualifiedNameAnalyzer->getFullyQualifiedName($attribute['name'], $attribute['start'], NamespaceUseAnalysis::TYPE_CLASS));
×
105
                if ('phpunit\framework\attributes\test' === $attributeName) {
×
UNCOV
106
                    return true;
×
107
                }
108
            }
109
        }
110

111
        return false;
×
112
    }
113
}
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