• 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

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
 * @no-named-arguments Parameter names are not covered by the backward compatibility promise.
30
 */
31
abstract class AbstractPhpUnitFixer extends AbstractFixer
32
{
33
    use DocBlockAnnotationTrait;
34

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

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

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

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

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

64
            if (null === $index) {
×
65
                return;
×
66
            }
67

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

71
            if (!str_starts_with($loweredContent, 'assert')) {
×
72
                continue;
×
73
            }
74

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

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

82
            if (!$functionsAnalyzer->isTheSameClassCall($tokens, $index)) {
×
83
                continue;
×
84
            }
85

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

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

102
        $fullyQualifiedNameAnalyzer = new FullyQualifiedNameAnalyzer($tokens);
×
103

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

113
        return false;
×
114
    }
115
}
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