• 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/Transformer/UseTransformer.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\Transformer;
16

17
use PhpCsFixer\Tokenizer\AbstractTransformer;
18
use PhpCsFixer\Tokenizer\CT;
19
use PhpCsFixer\Tokenizer\FCT;
20
use PhpCsFixer\Tokenizer\Token;
21
use PhpCsFixer\Tokenizer\Tokens;
22

23
/**
24
 * Transform T_USE into:
25
 * - CT::T_USE_TRAIT for imports,
26
 * - CT::T_USE_LAMBDA for lambda variable uses.
27
 *
28
 * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
29
 *
30
 * @internal
31
 *
32
 * @no-named-arguments Parameter names are not covered by the backward compatibility promise.
33
 */
34
final class UseTransformer extends AbstractTransformer
35
{
36
    private const CLASS_TYPES = [\T_TRAIT, FCT::T_ENUM];
37

38
    public function getPriority(): int
39
    {
40
        // Should run after CurlyBraceTransformer and before TypeColonTransformer
41
        return -5;
2✔
42
    }
43

44
    public function getRequiredPhpVersionId(): int
45
    {
46
        return 5_03_00;
3✔
47
    }
48

49
    public function process(Tokens $tokens, Token $token, int $index): void
50
    {
51
        if ($token->isGivenKind(\T_USE) && $this->isUseForLambda($tokens, $index)) {
10✔
52
            $tokens[$index] = new Token([CT::T_USE_LAMBDA, $token->getContent()]);
1✔
53

54
            return;
1✔
55
        }
56

57
        // Only search inside class/trait body for `T_USE` for traits.
58
        // Cannot import traits inside interfaces or anywhere else
59

60
        if ($token->isGivenKind(\T_CLASS)) {
10✔
61
            if ($tokens[$tokens->getPrevMeaningfulToken($index)]->isGivenKind(\T_DOUBLE_COLON)) {
4✔
62
                return;
×
63
            }
64
        } elseif (!$token->isGivenKind(self::CLASS_TYPES)) {
10✔
65
            return;
10✔
66
        }
67

68
        $index = $tokens->getNextTokenOfKind($index, ['{']);
5✔
69
        $innerLimit = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index);
5✔
70

71
        while ($index < $innerLimit) {
5✔
72
            $token = $tokens[++$index];
5✔
73

74
            if (!$token->isGivenKind(\T_USE)) {
5✔
75
                continue;
5✔
76
            }
77

78
            if ($this->isUseForLambda($tokens, $index)) {
4✔
79
                $tokens[$index] = new Token([CT::T_USE_LAMBDA, $token->getContent()]);
2✔
80
            } else {
81
                $tokens[$index] = new Token([CT::T_USE_TRAIT, $token->getContent()]);
4✔
82
            }
83
        }
84
    }
85

86
    public function getCustomTokens(): array
87
    {
88
        return [CT::T_USE_TRAIT, CT::T_USE_LAMBDA];
10✔
89
    }
90

91
    /**
92
     * Check if token under given index is `use` statement for lambda function.
93
     */
94
    private function isUseForLambda(Tokens $tokens, int $index): bool
95
    {
96
        $nextToken = $tokens[$tokens->getNextMeaningfulToken($index)];
9✔
97

98
        // test `function () use ($foo) {}` case
99
        return $nextToken->equals('(');
9✔
100
    }
101
}
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