@@ -64,6 +64,7 @@ final class ContextFactory
64
64
public function createFromReflector (Reflector $ reflector ) : Context
65
65
{
66
66
if ($ reflector instanceof ReflectionClass) {
67
+ /** @var ReflectionClass<object> $reflector */
67
68
return $ this ->createFromReflectionClass ($ reflector );
68
69
}
69
70
@@ -90,6 +91,7 @@ private function createFromReflectionParameter(ReflectionParameter $parameter) :
90
91
{
91
92
$ class = $ parameter ->getDeclaringClass ();
92
93
if ($ class ) {
94
+ /** @var ReflectionClass<object> $class */
93
95
return $ this ->createFromReflectionClass ($ class );
94
96
}
95
97
@@ -111,6 +113,9 @@ private function createFromReflectionClassConstant(ReflectionClassConstant $cons
111
113
return $ this ->createFromReflectionClass ($ constant ->getDeclaringClass ());
112
114
}
113
115
116
+ /**
117
+ * @param ReflectionClass<object> $class
118
+ */
114
119
private function createFromReflectionClass (ReflectionClass $ class ) : Context
115
120
{
116
121
$ fileName = $ class ->getFileName ();
@@ -188,6 +193,8 @@ public function createForNamespace(string $namespace, string $fileContents) : Co
188
193
189
194
/**
190
195
* Deduce the name from tokens when we are at the T_NAMESPACE token.
196
+ *
197
+ * @param ArrayIterator<int, string|array{0:int,1:string,2:int}> $tokens
191
198
*/
192
199
private function parseNamespace (ArrayIterator $ tokens ) : string
193
200
{
@@ -207,6 +214,8 @@ private function parseNamespace(ArrayIterator $tokens) : string
207
214
/**
208
215
* Deduce the names of all imports when we are at the T_USE token.
209
216
*
217
+ * @param ArrayIterator<int, string|array{0:int,1:string,2:int}> $tokens
218
+ *
210
219
* @return string[]
211
220
*/
212
221
private function parseUseStatement (ArrayIterator $ tokens ) : array
@@ -231,6 +240,8 @@ private function parseUseStatement(ArrayIterator $tokens) : array
231
240
232
241
/**
233
242
* Fast-forwards the iterator as longs as we don't encounter a T_STRING or T_NS_SEPARATOR token.
243
+ *
244
+ * @param ArrayIterator<int, string|array{0:int,1:string,2:int}> $tokens
234
245
*/
235
246
private function skipToNextStringOrNamespaceSeparator (ArrayIterator $ tokens ) : void
236
247
{
@@ -243,6 +254,8 @@ private function skipToNextStringOrNamespaceSeparator(ArrayIterator $tokens) : v
243
254
* Deduce the namespace name and alias of an import when we are at the T_USE token or have not reached the end of
244
255
* a USE statement yet. This will return a key/value array of the alias => namespace.
245
256
*
257
+ * @param ArrayIterator<int, string|array{0:int,1:string,2:int}> $tokens
258
+ *
246
259
* @return string[]
247
260
*
248
261
* @psalm-suppress TypeDoesNotContainType
@@ -264,7 +277,7 @@ private function extractUseStatements(ArrayIterator $tokens) : array
264
277
switch ($ tokenId ) {
265
278
case T_STRING :
266
279
case T_NS_SEPARATOR :
267
- $ currentNs .= $ tokenValue ;
280
+ $ currentNs .= ( string ) $ tokenValue ;
268
281
$ currentAlias = $ tokenValue ;
269
282
break ;
270
283
case T_CURLY_OPEN :
@@ -300,17 +313,17 @@ private function extractUseStatements(ArrayIterator $tokens) : array
300
313
switch ($ tokenId ) {
301
314
case T_STRING :
302
315
case T_NS_SEPARATOR :
303
- $ currentNs .= $ tokenValue ;
316
+ $ currentNs .= ( string ) $ tokenValue ;
304
317
$ currentAlias = $ tokenValue ;
305
318
break ;
306
319
case T_AS :
307
320
$ state = 'grouped-alias ' ;
308
321
break ;
309
322
case self ::T_LITERAL_USE_SEPARATOR :
310
- $ state = 'grouped ' ;
311
- $ extractedUseStatements [$ currentAlias ] = $ currentNs ;
312
- $ currentNs = $ groupedNs ;
313
- $ currentAlias = '' ;
323
+ $ state = 'grouped ' ;
324
+ $ extractedUseStatements [( string ) $ currentAlias ] = $ currentNs ;
325
+ $ currentNs = $ groupedNs ;
326
+ $ currentAlias = '' ;
314
327
break ;
315
328
case self ::T_LITERAL_END_OF_USE :
316
329
$ state = 'end ' ;
@@ -325,10 +338,10 @@ private function extractUseStatements(ArrayIterator $tokens) : array
325
338
$ currentAlias = $ tokenValue ;
326
339
break ;
327
340
case self ::T_LITERAL_USE_SEPARATOR :
328
- $ state = 'grouped ' ;
329
- $ extractedUseStatements [$ currentAlias ] = $ currentNs ;
330
- $ currentNs = $ groupedNs ;
331
- $ currentAlias = '' ;
341
+ $ state = 'grouped ' ;
342
+ $ extractedUseStatements [( string ) $ currentAlias ] = $ currentNs ;
343
+ $ currentNs = $ groupedNs ;
344
+ $ currentAlias = '' ;
332
345
break ;
333
346
case self ::T_LITERAL_END_OF_USE :
334
347
$ state = 'end ' ;
@@ -346,7 +359,7 @@ private function extractUseStatements(ArrayIterator $tokens) : array
346
359
}
347
360
348
361
if ($ groupedNs !== $ currentNs ) {
349
- $ extractedUseStatements [$ currentAlias ] = $ currentNs ;
362
+ $ extractedUseStatements [( string ) $ currentAlias ] = $ currentNs ;
350
363
}
351
364
352
365
return $ extractedUseStatements ;
0 commit comments