• 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

95.45
/src/Tokenizer/Analyzer/PhpUnitTestCaseAnalyzer.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\Tokenizer\Analyzer;
16

17
use PhpCsFixer\Preg;
18
use PhpCsFixer\Tokenizer\Tokens;
19

20
/**
21
 * @internal
22
 *
23
 * @no-named-arguments Parameter names are not covered by the backward compatibility promise.
24
 */
25
final class PhpUnitTestCaseAnalyzer
26
{
27
    /**
28
     * Returns an indices of PHPUnit classes in reverse appearance order.
29
     * Order is important - it's reverted, so if we inject tokens into collection,
30
     * we do it for bottom of file first, and then to the top of the file, so we
31
     * mitigate risk of not visiting whole collections (final indices).
32
     *
33
     * @return iterable<array{0: int, 1: int}> array of [int start, int end] indices from later to earlier classes
34
     */
35
    public function findPhpUnitClasses(Tokens $tokens): iterable
36
    {
37
        for ($index = $tokens->count() - 1; $index > 0; --$index) {
19✔
38
            if (!$this->isPhpUnitClass($tokens, $index)) {
17✔
39
                continue;
17✔
40
            }
41

42
            $startIndex = $tokens->getNextTokenOfKind($index, ['{']);
12✔
43
            \assert(\is_int($startIndex));
12✔
44

45
            $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $startIndex);
12✔
46

47
            yield [$startIndex, $endIndex];
12✔
48
        }
49
    }
50

51
    private function isPhpUnitClass(Tokens $tokens, int $index): bool
52
    {
53
        if (!$tokens[$index]->isGivenKind(\T_CLASS)) {
17✔
54
            return false;
17✔
55
        }
56

57
        $extendsIndex = $tokens->getNextTokenOfKind($index, ['{', [\T_EXTENDS]]);
17✔
58

59
        if (!$tokens[$extendsIndex]->isGivenKind(\T_EXTENDS)) {
17✔
60
            return false;
6✔
61
        }
62

63
        if (Preg::match('/(?:Test|TestCase)$/', $tokens[$index]->getContent())) {
12✔
64
            return true;
×
65
        }
66

67
        while (null !== $index = $tokens->getNextMeaningfulToken($index)) {
12✔
68
            if ($tokens[$index]->equals('{')) {
12✔
69
                break; // end of class signature
1✔
70
            }
71

72
            if (!$tokens[$index]->isGivenKind(\T_STRING)) {
12✔
73
                continue; // not part of extends nor part of implements; so continue
8✔
74
            }
75

76
            if (Preg::match('/(?:Test|TestCase)(?:Interface)?$/', $tokens[$index]->getContent())) {
12✔
77
                return true;
12✔
78
            }
79
        }
80

81
        return false;
1✔
82
    }
83
}
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