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

keradus / PHP-CS-Fixer / 19958239208

05 Dec 2025 09:13AM UTC coverage: 93.181% (-1.0%) from 94.158%
19958239208

push

github

keradus
chore: .php-cs-fixer.dist.php - remove no longer needed rule, 'expectedDeprecation' annotation does not exist for long time

28928 of 31045 relevant lines covered (93.18%)

44.49 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
 * @TODO v4: previously was mareked as internal - yet it leaked to public interface of `DocBlock`, consider making it so again.
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 non-empty-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
     * @var non-empty-string
46
     */
47
    private string $shortName;
48

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

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

59
    /**
60
     * The start index of the namespace declaration in the analysed Tokens.
61
     */
62
    private int $startIndex;
63

64
    /**
65
     * The end index of the namespace declaration in the analysed Tokens.
66
     */
67
    private int $endIndex;
68

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

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

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

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

108
        $this->type = $type;
7✔
109
        $this->fullName = $fullName;
7✔
110
        $this->shortName = $shortName;
7✔
111
        $this->isAliased = $isAliased;
7✔
112
        $this->isInMulti = $isInMulti;
7✔
113
        $this->startIndex = $startIndex;
7✔
114
        $this->endIndex = $endIndex;
7✔
115
        $this->chunkStartIndex = $chunkStartIndex;
7✔
116
        $this->chunkEndIndex = $chunkEndIndex;
7✔
117
    }
118

119
    /**
120
     * @return non-empty-string
121
     */
122
    public function getFullName(): string
123
    {
124
        return $this->fullName;
1✔
125
    }
126

127
    /**
128
     * @return non-empty-string
129
     */
130
    public function getShortName(): string
131
    {
132
        return $this->shortName;
1✔
133
    }
134

135
    public function isAliased(): bool
136
    {
137
        return $this->isAliased;
1✔
138
    }
139

140
    public function isInMulti(): bool
141
    {
142
        return $this->isInMulti;
1✔
143
    }
144

145
    public function getStartIndex(): int
146
    {
147
        return $this->startIndex;
1✔
148
    }
149

150
    public function getEndIndex(): int
151
    {
152
        return $this->endIndex;
1✔
153
    }
154

155
    public function getChunkStartIndex(): ?int
156
    {
157
        return $this->chunkStartIndex;
×
158
    }
159

160
    public function getChunkEndIndex(): ?int
161
    {
162
        return $this->chunkEndIndex;
×
163
    }
164

165
    /**
166
     * @return self::TYPE_*
167
     */
168
    public function getType(): int
169
    {
170
        return $this->type;
1✔
171
    }
172

173
    /**
174
     * @return _ImportType
175
     */
176
    public function getHumanFriendlyType(): string
177
    {
178
        return [
×
179
            self::TYPE_CLASS => 'class',
×
180
            self::TYPE_FUNCTION => 'function',
×
181
            self::TYPE_CONSTANT => 'constant',
×
182
        ][$this->type];
×
183
    }
184

185
    public function isClass(): bool
186
    {
187
        return self::TYPE_CLASS === $this->type;
1✔
188
    }
189

190
    public function isFunction(): bool
191
    {
192
        return self::TYPE_FUNCTION === $this->type;
1✔
193
    }
194

195
    public function isConstant(): bool
196
    {
197
        return self::TYPE_CONSTANT === $this->type;
1✔
198
    }
199
}
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