@@ -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 ();
@@ -190,6 +195,8 @@ public function createForNamespace(string $namespace, string $fileContents) : Co
190
195
191
196
/**
192
197
* Deduce the name from tokens when we are at the T_NAMESPACE token.
198
+ *
199
+ * @param ArrayIterator<int, string|array{0:int,1:string,2:int}> $tokens
193
200
*/
194
201
private function parseNamespace (ArrayIterator $ tokens ) : string
195
202
{
@@ -209,6 +216,8 @@ private function parseNamespace(ArrayIterator $tokens) : string
209
216
/**
210
217
* Deduce the names of all imports when we are at the T_USE token.
211
218
*
219
+ * @param ArrayIterator<int, string|array{0:int,1:string,2:int}> $tokens
220
+ *
212
221
* @return string[]
213
222
*/
214
223
private function parseUseStatement (ArrayIterator $ tokens ) : array
@@ -233,6 +242,8 @@ private function parseUseStatement(ArrayIterator $tokens) : array
233
242
234
243
/**
235
244
* Fast-forwards the iterator as longs as we don't encounter a T_STRING or T_NS_SEPARATOR token.
245
+ *
246
+ * @param ArrayIterator<int, string|array{0:int,1:string,2:int}> $tokens
236
247
*/
237
248
private function skipToNextStringOrNamespaceSeparator (ArrayIterator $ tokens ) : void
238
249
{
@@ -245,6 +256,8 @@ private function skipToNextStringOrNamespaceSeparator(ArrayIterator $tokens) : v
245
256
* Deduce the namespace name and alias of an import when we are at the T_USE token or have not reached the end of
246
257
* a USE statement yet. This will return a key/value array of the alias => namespace.
247
258
*
259
+ * @param ArrayIterator<int, string|array{0:int,1:string,2:int}> $tokens
260
+ *
248
261
* @return string[]
249
262
*
250
263
* @psalm-suppress TypeDoesNotContainType
@@ -266,7 +279,7 @@ private function extractUseStatements(ArrayIterator $tokens) : array
266
279
switch ($ tokenId ) {
267
280
case T_STRING :
268
281
case T_NS_SEPARATOR :
269
- $ currentNs .= $ tokenValue ;
282
+ $ currentNs .= ( string ) $ tokenValue ;
270
283
$ currentAlias = $ tokenValue ;
271
284
break ;
272
285
case T_CURLY_OPEN :
@@ -304,17 +317,17 @@ private function extractUseStatements(ArrayIterator $tokens) : array
304
317
switch ($ tokenId ) {
305
318
case T_STRING :
306
319
case T_NS_SEPARATOR :
307
- $ currentNs .= $ tokenValue ;
320
+ $ currentNs .= ( string ) $ tokenValue ;
308
321
$ currentAlias = $ tokenValue ;
309
322
break ;
310
323
case T_AS :
311
324
$ state = 'grouped-alias ' ;
312
325
break ;
313
326
case self ::T_LITERAL_USE_SEPARATOR :
314
- $ state = 'grouped ' ;
315
- $ extractedUseStatements [$ currentAlias ] = $ currentNs ;
316
- $ currentNs = $ groupedNs ;
317
- $ currentAlias = '' ;
327
+ $ state = 'grouped ' ;
328
+ $ extractedUseStatements [( string ) $ currentAlias ] = $ currentNs ;
329
+ $ currentNs = $ groupedNs ;
330
+ $ currentAlias = '' ;
318
331
break ;
319
332
case self ::T_LITERAL_END_OF_USE :
320
333
$ state = 'end ' ;
@@ -330,10 +343,10 @@ private function extractUseStatements(ArrayIterator $tokens) : array
330
343
$ currentAlias = $ tokenValue ;
331
344
break ;
332
345
case self ::T_LITERAL_USE_SEPARATOR :
333
- $ state = 'grouped ' ;
334
- $ extractedUseStatements [$ currentAlias ] = $ currentNs ;
335
- $ currentNs = $ groupedNs ;
336
- $ currentAlias = '' ;
346
+ $ state = 'grouped ' ;
347
+ $ extractedUseStatements [( string ) $ currentAlias ] = $ currentNs ;
348
+ $ currentNs = $ groupedNs ;
349
+ $ currentAlias = '' ;
337
350
break ;
338
351
case self ::T_LITERAL_END_OF_USE :
339
352
$ state = 'end ' ;
@@ -351,7 +364,7 @@ private function extractUseStatements(ArrayIterator $tokens) : array
351
364
}
352
365
353
366
if ($ groupedNs !== $ currentNs ) {
354
- $ extractedUseStatements [$ currentAlias ] = $ currentNs ;
367
+ $ extractedUseStatements [( string ) $ currentAlias ] = $ currentNs ;
355
368
}
356
369
357
370
return $ extractedUseStatements ;
0 commit comments