7
7
use PhpParser \Node ;
8
8
use PhpParser \NodeTraverser ;
9
9
use PhpParser \NodeVisitor \NameResolver ;
10
+ use PhpParser \Token ;
10
11
use PHPStan \Analyser \Ignore \IgnoreLexer ;
11
12
use PHPStan \Analyser \Ignore \IgnoreParseException ;
12
13
use PHPStan \DependencyInjection \Container ;
17
18
use function array_values ;
18
19
use function count ;
19
20
use function in_array ;
20
- use function is_string ;
21
21
use function str_contains ;
22
22
use function strlen ;
23
23
use function strpos ;
@@ -64,8 +64,7 @@ public function parseString(string $sourceCode): array
64
64
$ errorHandler = new Collecting ();
65
65
$ nodes = $ this ->parser ->parse ($ sourceCode , $ errorHandler );
66
66
67
- /** @var list<string|array{0:int,1:string,2:int}> $tokens */
68
- $ tokens = $ this ->lexer ->getTokens ();
67
+ $ tokens = $ this ->parser ->getTokens ();
69
68
if ($ errorHandler ->hasErrors ()) {
70
69
throw new ParserErrorsException ($ errorHandler ->getErrors (), null );
71
70
}
@@ -101,7 +100,7 @@ public function parseString(string $sourceCode): array
101
100
}
102
101
103
102
/**
104
- * @param list<string|array{0:int,1:string,2:int}> $tokens
103
+ * @param Token[] $tokens
105
104
* @return array{lines: array<int, non-empty-list<string>|null>, errors: array<int, non-empty-list<string>>}
106
105
*/
107
106
private function getLinesToIgnore (array $ tokens ): array
@@ -111,12 +110,8 @@ private function getLinesToIgnore(array $tokens): array
111
110
$ pendingToken = null ;
112
111
$ errors = [];
113
112
foreach ($ tokens as $ token ) {
114
- if (is_string ($ token )) {
115
- continue ;
116
- }
117
-
118
- $ type = $ token [0 ];
119
- $ line = $ token [2 ];
113
+ $ type = $ token ->id ;
114
+ $ line = $ token ->line ;
120
115
if ($ type !== T_COMMENT && $ type !== T_DOC_COMMENT ) {
121
116
if ($ type !== T_WHITESPACE ) {
122
117
if ($ pendingToken !== null ) {
@@ -147,14 +142,14 @@ private function getLinesToIgnore(array $tokens): array
147
142
continue ;
148
143
}
149
144
150
- $ text = $ token[ 1 ] ;
145
+ $ text = $ token-> text ;
151
146
$ isNextLine = str_contains ($ text , '@phpstan-ignore-next-line ' );
152
147
$ isCurrentLine = str_contains ($ text , '@phpstan-ignore-line ' );
153
148
if ($ isNextLine ) {
154
149
$ line ++;
155
150
}
156
151
if ($ isNextLine || $ isCurrentLine ) {
157
- $ line += substr_count ($ token[ 1 ] , "\n" );
152
+ $ line += substr_count ($ token-> text , "\n" );
158
153
159
154
$ lines [$ line ] = null ;
160
155
continue ;
@@ -167,20 +162,20 @@ private function getLinesToIgnore(array $tokens): array
167
162
168
163
$ ignoreLine = substr_count (substr ($ text , 0 , $ ignorePos ), "\n" ) - 1 ;
169
164
170
- if ($ previousToken !== null && $ previousToken[ 2 ] === $ line ) {
165
+ if ($ previousToken !== null && $ previousToken-> line === $ line ) {
171
166
try {
172
167
foreach ($ this ->parseIdentifiers ($ text , $ ignorePos ) as $ identifier ) {
173
168
$ lines [$ line ][] = $ identifier ;
174
169
}
175
170
} catch (IgnoreParseException $ e ) {
176
- $ errors [] = [$ token[ 2 ] + $ e ->getPhpDocLine () + $ ignoreLine , $ e ->getMessage ()];
171
+ $ errors [] = [$ token-> line + $ e ->getPhpDocLine () + $ ignoreLine , $ e ->getMessage ()];
177
172
}
178
173
179
174
continue ;
180
175
}
181
176
182
- $ line += substr_count ($ token[ 1 ] , "\n" );
183
- $ pendingToken = [$ text , $ ignorePos , $ token[ 2 ] + $ ignoreLine , $ line ];
177
+ $ line += substr_count ($ token-> text , "\n" );
178
+ $ pendingToken = [$ text , $ ignorePos , $ token-> line + $ ignoreLine , $ line ];
184
179
}
185
180
186
181
if ($ pendingToken !== null ) {
0 commit comments