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 count ;
18
19
use function implode ;
19
20
use function in_array ;
20
- use function is_string ;
21
21
use function preg_match_all ;
22
22
use function sprintf ;
23
23
use function str_contains ;
@@ -72,8 +72,7 @@ public function parseString(string $sourceCode): array
72
72
$ errorHandler = new Collecting ();
73
73
$ nodes = $ this ->parser ->parse ($ sourceCode , $ errorHandler );
74
74
75
- /** @var list<string|array{0:int,1:string,2:int}> $tokens */
76
- $ tokens = $ this ->lexer ->getTokens ();
75
+ $ tokens = $ this ->parser ->getTokens ();
77
76
if ($ errorHandler ->hasErrors ()) {
78
77
throw new ParserErrorsException ($ errorHandler ->getErrors (), null );
79
78
}
@@ -109,7 +108,7 @@ public function parseString(string $sourceCode): array
109
108
}
110
109
111
110
/**
112
- * @param list<string|array{0:int,1:string,2:int}> $tokens
111
+ * @param Token[] $tokens
113
112
* @return array{lines: array<int, non-empty-list<string>|null>, errors: array<int, non-empty-list<string>>}
114
113
*/
115
114
private function getLinesToIgnore (array $ tokens ): array
@@ -119,12 +118,8 @@ private function getLinesToIgnore(array $tokens): array
119
118
$ pendingToken = null ;
120
119
$ errors = [];
121
120
foreach ($ tokens as $ token ) {
122
- if (is_string ($ token )) {
123
- continue ;
124
- }
125
-
126
- $ type = $ token [0 ];
127
- $ line = $ token [2 ];
121
+ $ type = $ token ->id ;
122
+ $ line = $ token ->line ;
128
123
if ($ type !== T_COMMENT && $ type !== T_DOC_COMMENT ) {
129
124
if ($ type !== T_WHITESPACE ) {
130
125
if ($ pendingToken !== null ) {
@@ -155,7 +150,7 @@ private function getLinesToIgnore(array $tokens): array
155
150
continue ;
156
151
}
157
152
158
- $ text = $ token[ 1 ] ;
153
+ $ text = $ token-> text ;
159
154
$ isNextLine = str_contains ($ text , '@phpstan-ignore-next-line ' );
160
155
$ isCurrentLine = str_contains ($ text , '@phpstan-ignore-line ' );
161
156
@@ -204,20 +199,20 @@ private function getLinesToIgnore(array $tokens): array
204
199
205
200
$ ignoreLine = substr_count (substr ($ text , 0 , $ ignorePos ), "\n" ) - 1 ;
206
201
207
- if ($ previousToken !== null && $ previousToken[ 2 ] === $ line ) {
202
+ if ($ previousToken !== null && $ previousToken-> line === $ line ) {
208
203
try {
209
204
foreach ($ this ->parseIdentifiers ($ text , $ ignorePos ) as $ identifier ) {
210
205
$ lines [$ line ][] = $ identifier ;
211
206
}
212
207
} catch (IgnoreParseException $ e ) {
213
- $ errors [] = [$ token[ 2 ] + $ e ->getPhpDocLine () + $ ignoreLine , $ e ->getMessage ()];
208
+ $ errors [] = [$ token-> line + $ e ->getPhpDocLine () + $ ignoreLine , $ e ->getMessage ()];
214
209
}
215
210
216
211
continue ;
217
212
}
218
213
219
- $ line += substr_count ($ token[ 1 ] , "\n" );
220
- $ pendingToken = [$ text , $ ignorePos , $ token[ 2 ] + $ ignoreLine , $ line ];
214
+ $ line += substr_count ($ token-> text , "\n" );
215
+ $ pendingToken = [$ text , $ ignorePos , $ token-> line + $ ignoreLine , $ line ];
221
216
}
222
217
223
218
if ($ pendingToken !== null ) {
0 commit comments