• 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

88.0
/src/Fixer/Import/NoUnneededImportAliasFixer.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\Import;
16

17
use PhpCsFixer\AbstractFixer;
18
use PhpCsFixer\FixerDefinition\CodeSample;
19
use PhpCsFixer\FixerDefinition\FixerDefinition;
20
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
21
use PhpCsFixer\Tokenizer\CT;
22
use PhpCsFixer\Tokenizer\Tokens;
23

24
/**
25
 * @no-named-arguments Parameter names are not covered by the backward compatibility promise.
26
 */
27
final class NoUnneededImportAliasFixer extends AbstractFixer
28
{
29
    public function getDefinition(): FixerDefinitionInterface
30
    {
31
        return new FixerDefinition(
3✔
32
            'Imports should not be aliased as the same name.',
3✔
33
            [new CodeSample("<?php\nuse A\\B\\Foo as Foo;\n")]
3✔
34
        );
3✔
35
    }
36

37
    public function isCandidate(Tokens $tokens): bool
38
    {
39
        return $tokens->isAllTokenKindsFound([\T_USE, \T_AS]);
9✔
40
    }
41

42
    /**
43
     * {@inheritdoc}
44
     *
45
     * Must run before NoSinglelineWhitespaceBeforeSemicolonsFixer.
46
     * Must run after PhpUnitNamespacedFixer.
47
     */
48
    public function getPriority(): int
49
    {
50
        return 1;
1✔
51
    }
52

53
    protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
54
    {
55
        for ($index = \count($tokens) - 1; 0 <= $index; --$index) {
8✔
56
            if (!$tokens[$index]->isGivenKind(\T_AS)) {
8✔
57
                continue;
8✔
58
            }
59

60
            $aliasIndex = $tokens->getNextMeaningfulToken($index);
8✔
61

62
            if (!$tokens[$aliasIndex]->isGivenKind(\T_STRING)) {
8✔
63
                continue;
×
64
            }
65

66
            $importIndex = $tokens->getPrevMeaningfulToken($index);
8✔
67

68
            if (!$tokens[$importIndex]->isGivenKind(\T_STRING)) {
8✔
69
                continue;
×
70
            }
71

72
            if ($tokens[$importIndex]->getContent() !== $tokens[$aliasIndex]->getContent()) {
8✔
73
                continue;
2✔
74
            }
75

76
            do {
77
                $importIndex = $tokens->getPrevMeaningfulToken($importIndex);
8✔
78
            } while ($tokens[$importIndex]->isGivenKind([\T_NS_SEPARATOR, \T_STRING, \T_AS]) || $tokens[$importIndex]->equals(','));
8✔
79

80
            if ($tokens[$importIndex]->isGivenKind([CT::T_FUNCTION_IMPORT, CT::T_CONST_IMPORT])) {
8✔
81
                $importIndex = $tokens->getPrevMeaningfulToken($importIndex);
4✔
82
            }
83

84
            if (!$tokens[$importIndex]->isGivenKind([\T_USE, CT::T_GROUP_IMPORT_BRACE_OPEN])) {
8✔
85
                continue;
×
86
            }
87

88
            $tokens->clearTokenAndMergeSurroundingWhitespace($aliasIndex);
8✔
89
            $tokens->clearTokenAndMergeSurroundingWhitespace($index);
8✔
90
        }
91
    }
92
}
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