• 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

96.15
/src/Tokenizer/Analyzer/FullyQualifiedNameAnalyzer.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\Tokenizer\Analyzer\Analysis\NamespaceAnalysis;
18
use PhpCsFixer\Tokenizer\Analyzer\Analysis\NamespaceUseAnalysis;
19
use PhpCsFixer\Tokenizer\Tokens;
20

21
/**
22
 * @internal
23
 *
24
 * @no-named-arguments Parameter names are not covered by the backward compatibility promise.
25
 */
26
final class FullyQualifiedNameAnalyzer
27
{
28
    private Tokens $tokens;
29

30
    /**
31
     * @var list<NamespaceAnalysis>
32
     */
33
    private array $namespaceAnalyses = [];
34

35
    /**
36
     * @var array<int, list<NamespaceUseAnalysis>>
37
     */
38
    private array $namespaceUseAnalyses = [];
39

40
    public function __construct(Tokens $tokens)
41
    {
42
        $this->tokens = $tokens;
21✔
43
    }
44

45
    /**
46
     * @param NamespaceUseAnalysis::TYPE_* $importType
47
     */
48
    public function getFullyQualifiedName(string $name, int $indexInNamespace, int $importType): string
49
    {
50
        return ltrim($this->getFullyQualifiedNameWithPossiblyLeadingSlash($name, $indexInNamespace, $importType), '\\');
21✔
51
    }
52

53
    /**
54
     * @param NamespaceUseAnalysis::TYPE_* $importType
55
     */
56
    private function getFullyQualifiedNameWithPossiblyLeadingSlash(string $name, int $indexInNamespace, int $importType): string
57
    {
58
        if ('\\' === $name[0]) {
21✔
59
            return $name;
1✔
60
        }
61

62
        $namespaceAnalysis = $this->getNamespaceAnalysis($indexInNamespace);
20✔
63

64
        $this->namespaceUseAnalyses[$namespaceAnalysis->getStartIndex()] ??= (new NamespaceUsesAnalyzer())->getDeclarationsInNamespace($this->tokens, $namespaceAnalysis);
20✔
65
        \assert(isset($this->namespaceUseAnalyses[$namespaceAnalysis->getStartIndex()]));
20✔
66

67
        $declarations = [];
20✔
68
        foreach ($this->namespaceUseAnalyses[$namespaceAnalysis->getStartIndex()] as $namespaceUseAnalysis) {
20✔
69
            if ($namespaceUseAnalysis->getType() !== $importType) {
15✔
70
                continue;
3✔
71
            }
72
            $declarations[strtolower($namespaceUseAnalysis->getShortName())] = $namespaceUseAnalysis->getFullName();
15✔
73
        }
74

75
        $lowercaseName = strtolower($name);
20✔
76
        foreach ($declarations as $lowercaseShortName => $fullName) {
20✔
77
            if ($lowercaseName === $lowercaseShortName) {
15✔
78
                return $fullName;
11✔
79
            }
80

81
            if (!str_starts_with($lowercaseName, $lowercaseShortName.'\\')) {
5✔
82
                continue;
1✔
83
            }
84

85
            return $fullName.substr($name, \strlen($lowercaseShortName));
4✔
86
        }
87

88
        return $namespaceAnalysis->getFullName().'\\'.$name;
5✔
89
    }
90

91
    private function getNamespaceAnalysis(int $index): NamespaceAnalysis
92
    {
93
        foreach ($this->namespaceAnalyses as $namespace) {
20✔
94
            if ($namespace->getScopeStartIndex() <= $index && $namespace->getScopeEndIndex() >= $index) {
1✔
95
                return $namespace;
×
96
            }
97
        }
98

99
        $namespace = (new NamespacesAnalyzer())->getNamespaceAt($this->tokens, $index);
20✔
100

101
        $this->namespaceAnalyses[] = $namespace;
20✔
102

103
        return $namespace;
20✔
104
    }
105
}
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