• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

keradus / PHP-CS-Fixer / 17253322895

26 Aug 2025 11:52PM UTC coverage: 94.753% (+0.008%) from 94.745%
17253322895

push

github

keradus
add to git-blame-ignore-revs

28316 of 29884 relevant lines covered (94.75%)

45.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.0
/src/Tokenizer/Analyzer/Analysis/NamespaceUseAnalysis.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\Analysis;
16

17
/**
18
 * @readonly
19
 *
20
 * @internal
21
 *
22
 * @phpstan-type _ImportType 'class'|'constant'|'function'
23
 *
24
 * @author VeeWee <toonverwerft@gmail.com>
25
 * @author Greg Korba <greg@codito.dev>
26
 *
27
 * @no-named-arguments Parameter names are not covered by the backward compatibility promise.
28
 */
29
final class NamespaceUseAnalysis
30
{
31
    public const TYPE_CLASS = 1; // "classy" could be class, interface or trait
32
    public const TYPE_FUNCTION = 2;
33
    public const TYPE_CONSTANT = 3;
34

35
    /**
36
     * The fully qualified use namespace.
37
     *
38
     * @var class-string
39
     */
40
    private string $fullName;
41

42
    /**
43
     * The short version of use namespace or the alias name in case of aliased use statements.
44
     */
45
    private string $shortName;
46

47
    /**
48
     * Is the use statement part of multi-use (`use A, B, C;`, `use A\{B, C};`)?
49
     */
50
    private bool $isInMulti;
51

52
    /**
53
     * Is the use statement being aliased?
54
     */
55
    private bool $isAliased;
56

57
    /**
58
     * The start index of the namespace declaration in the analyzed Tokens.
59
     */
60
    private int $startIndex;
61

62
    /**
63
     * The end index of the namespace declaration in the analyzed Tokens.
64
     */
65
    private int $endIndex;
66

67
    /**
68
     * The start index of the single import in the multi-use statement.
69
     */
70
    private ?int $chunkStartIndex;
71

72
    /**
73
     * The end index of the single import in the multi-use statement.
74
     */
75
    private ?int $chunkEndIndex;
76

77
    /**
78
     * The type of import: class, function or constant.
79
     *
80
     * @var self::TYPE_*
81
     */
82
    private int $type;
83

84
    /**
85
     * @param self::TYPE_* $type
86
     * @param class-string $fullName
87
     */
88
    public function __construct(
89
        int $type,
90
        string $fullName,
91
        string $shortName,
92
        bool $isAliased,
93
        bool $isInMulti,
94
        int $startIndex,
95
        int $endIndex,
96
        ?int $chunkStartIndex = null,
97
        ?int $chunkEndIndex = null
98
    ) {
99
        if (true === $isInMulti && (null === $chunkStartIndex || null === $chunkEndIndex)) {
8✔
100
            throw new \LogicException('Chunk start and end index must be set when the import is part of a multi-use statement.');
1✔
101
        }
102

103
        $this->type = $type;
7✔
104
        $this->fullName = $fullName;
7✔
105
        $this->shortName = $shortName;
7✔
106
        $this->isAliased = $isAliased;
7✔
107
        $this->isInMulti = $isInMulti;
7✔
108
        $this->startIndex = $startIndex;
7✔
109
        $this->endIndex = $endIndex;
7✔
110
        $this->chunkStartIndex = $chunkStartIndex;
7✔
111
        $this->chunkEndIndex = $chunkEndIndex;
7✔
112
    }
113

114
    /**
115
     * @return class-string
116
     */
117
    public function getFullName(): string
118
    {
119
        return $this->fullName;
1✔
120
    }
121

122
    public function getShortName(): string
123
    {
124
        return $this->shortName;
1✔
125
    }
126

127
    public function isAliased(): bool
128
    {
129
        return $this->isAliased;
1✔
130
    }
131

132
    public function isInMulti(): bool
133
    {
134
        return $this->isInMulti;
1✔
135
    }
136

137
    public function getStartIndex(): int
138
    {
139
        return $this->startIndex;
1✔
140
    }
141

142
    public function getEndIndex(): int
143
    {
144
        return $this->endIndex;
1✔
145
    }
146

147
    public function getChunkStartIndex(): ?int
148
    {
149
        return $this->chunkStartIndex;
×
150
    }
151

152
    public function getChunkEndIndex(): ?int
153
    {
154
        return $this->chunkEndIndex;
×
155
    }
156

157
    /**
158
     * @return self::TYPE_*
159
     */
160
    public function getType(): int
161
    {
162
        return $this->type;
1✔
163
    }
164

165
    /**
166
     * @return _ImportType
167
     */
168
    public function getHumanFriendlyType(): string
169
    {
170
        return [
×
171
            self::TYPE_CLASS => 'class',
×
172
            self::TYPE_FUNCTION => 'function',
×
173
            self::TYPE_CONSTANT => 'constant',
×
174
        ][$this->type];
×
175
    }
176

177
    public function isClass(): bool
178
    {
179
        return self::TYPE_CLASS === $this->type;
1✔
180
    }
181

182
    public function isFunction(): bool
183
    {
184
        return self::TYPE_FUNCTION === $this->type;
1✔
185
    }
186

187
    public function isConstant(): bool
188
    {
189
        return self::TYPE_CONSTANT === $this->type;
1✔
190
    }
191
}
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