11
11
use PHPStan \PhpDoc \Tag \MethodTag ;
12
12
use PHPStan \PhpDoc \Tag \MethodTagParameter ;
13
13
use PHPStan \PhpDoc \Tag \MixinTag ;
14
+ use PHPStan \PhpDoc \Tag \ParamClosureThisTag ;
14
15
use PHPStan \PhpDoc \Tag \ParamOutTag ;
15
16
use PHPStan \PhpDoc \Tag \ParamTag ;
16
17
use PHPStan \PhpDoc \Tag \PropertyTag ;
30
31
use PHPStan \PhpDocParser \Ast \PhpDoc \TemplateTagValueNode ;
31
32
use PHPStan \Reflection \PassedByReference ;
32
33
use PHPStan \Rules \PhpDoc \UnresolvableTypeHelper ;
33
- use PHPStan \TrinaryLogic ;
34
- use PHPStan \Type \CallableType ;
35
34
use PHPStan \Type \Generic \TemplateTypeFactory ;
36
35
use PHPStan \Type \Generic \TemplateTypeMap ;
37
36
use PHPStan \Type \Generic \TemplateTypeScope ;
38
37
use PHPStan \Type \Generic \TemplateTypeVariance ;
39
38
use PHPStan \Type \MixedType ;
40
- use PHPStan \Type \ObjectWithoutClassType ;
41
39
use PHPStan \Type \Type ;
42
40
use PHPStan \Type \TypeCombinator ;
43
41
use function array_key_exists ;
@@ -345,31 +343,6 @@ public function resolveTemplateTags(PhpDocNode $phpDocNode, NameScope $nameScope
345
343
public function resolveParamTags (PhpDocNode $ phpDocNode , NameScope $ nameScope ): array
346
344
{
347
345
$ resolved = [];
348
- $ immediatelyInvokedCallableParameters = [];
349
- foreach (['@param-immediately-invoked-callable ' , '@phpstan-param-immediately-invoked-callable ' ] as $ tagName ) {
350
- foreach ($ phpDocNode ->getParamImmediatelyInvokedCallableTagValues ($ tagName ) as $ tagValue ) {
351
- $ parameterName = substr ($ tagValue ->parameterName , 1 );
352
- $ immediatelyInvokedCallableParameters [$ parameterName ] = TrinaryLogic::createYes ();
353
- }
354
- }
355
- foreach (['@param-later-invoked-callable ' , '@phpstan-param-later-invoked-callable ' ] as $ tagName ) {
356
- foreach ($ phpDocNode ->getParamLaterInvokedCallableTagValues ($ tagName ) as $ tagValue ) {
357
- $ parameterName = substr ($ tagValue ->parameterName , 1 );
358
- $ immediatelyInvokedCallableParameters [$ parameterName ] = TrinaryLogic::createNo ();
359
- }
360
- }
361
-
362
- $ unusedImmediatelyInvokedCallableParameters = $ immediatelyInvokedCallableParameters ;
363
-
364
- $ closureThisTypes = [];
365
- foreach (['@param-closure-this ' , '@phpstan-param-closure-this ' ] as $ tagName ) {
366
- foreach ($ phpDocNode ->getParamClosureThisTagValues ($ tagName ) as $ tagValue ) {
367
- $ parameterName = substr ($ tagValue ->parameterName , 1 );
368
- $ closureThisTypes [$ parameterName ] = TypeCombinator::intersect (new ObjectWithoutClassType (), $ this ->typeNodeResolver ->resolve ($ tagValue ->type , $ nameScope ));
369
- }
370
- }
371
-
372
- $ unusedClosureThisTypes = $ closureThisTypes ;
373
346
374
347
foreach (['@param ' , '@phan-param ' , '@psalm-param ' , '@phpstan-param ' ] as $ tagName ) {
375
348
foreach ($ phpDocNode ->getParamTagValues ($ tagName ) as $ tagValue ) {
@@ -379,53 +352,13 @@ public function resolveParamTags(PhpDocNode $phpDocNode, NameScope $nameScope):
379
352
continue ;
380
353
}
381
354
382
- if (array_key_exists ($ parameterName , $ immediatelyInvokedCallableParameters )) {
383
- $ immediatelyInvokedCallable = $ immediatelyInvokedCallableParameters [$ parameterName ];
384
- unset($ unusedImmediatelyInvokedCallableParameters [$ parameterName ]);
385
- } else {
386
- $ immediatelyInvokedCallable = TrinaryLogic::createMaybe ();
387
- }
388
-
389
- if (array_key_exists ($ parameterName , $ closureThisTypes )) {
390
- $ closureThisType = $ closureThisTypes [$ parameterName ];
391
- unset($ unusedClosureThisTypes [$ parameterName ]);
392
- } else {
393
- $ closureThisType = null ;
394
- }
395
-
396
355
$ resolved [$ parameterName ] = new ParamTag (
397
356
$ parameterType ,
398
357
$ tagValue ->isVariadic ,
399
- $ immediatelyInvokedCallable ,
400
- $ closureThisType ,
401
358
);
402
359
}
403
360
}
404
361
405
- foreach ($ unusedImmediatelyInvokedCallableParameters as $ parameterName => $ immediately ) {
406
- if (array_key_exists ($ parameterName , $ closureThisTypes )) {
407
- $ closureThisType = $ closureThisTypes [$ parameterName ];
408
- unset($ unusedClosureThisTypes [$ parameterName ]);
409
- } else {
410
- $ closureThisType = null ;
411
- }
412
- $ resolved [$ parameterName ] = new ParamTag (
413
- new CallableType (),
414
- false ,
415
- $ immediately ,
416
- $ closureThisType ,
417
- );
418
- }
419
-
420
- foreach ($ unusedClosureThisTypes as $ parameterName => $ closureThisType ) {
421
- $ resolved [$ parameterName ] = new ParamTag (
422
- new CallableType (),
423
- false ,
424
- TrinaryLogic::createMaybe (),
425
- $ closureThisType ,
426
- );
427
- }
428
-
429
362
return $ resolved ;
430
363
}
431
364
@@ -457,6 +390,44 @@ public function resolveParamOutTags(PhpDocNode $phpDocNode, NameScope $nameScope
457
390
return $ resolved ;
458
391
}
459
392
393
+ /**
394
+ * @return array<string, bool>
395
+ */
396
+ public function resolveParamImmediatelyInvokedCallable (PhpDocNode $ phpDocNode ): array
397
+ {
398
+ $ parameters = [];
399
+ foreach (['@param-immediately-invoked-callable ' , '@phpstan-param-immediately-invoked-callable ' ] as $ tagName ) {
400
+ foreach ($ phpDocNode ->getParamImmediatelyInvokedCallableTagValues ($ tagName ) as $ tagValue ) {
401
+ $ parameterName = substr ($ tagValue ->parameterName , 1 );
402
+ $ parameters [$ parameterName ] = true ;
403
+ }
404
+ }
405
+ foreach (['@param-later-invoked-callable ' , '@phpstan-param-later-invoked-callable ' ] as $ tagName ) {
406
+ foreach ($ phpDocNode ->getParamLaterInvokedCallableTagValues ($ tagName ) as $ tagValue ) {
407
+ $ parameterName = substr ($ tagValue ->parameterName , 1 );
408
+ $ parameters [$ parameterName ] = false ;
409
+ }
410
+ }
411
+
412
+ return $ parameters ;
413
+ }
414
+
415
+ /**
416
+ * @return array<string, ParamClosureThisTag>
417
+ */
418
+ public function resolveParamClosureThisTags (PhpDocNode $ phpDocNode , NameScope $ nameScope ): array
419
+ {
420
+ $ closureThisTypes = [];
421
+ foreach (['@param-closure-this ' , '@phpstan-param-closure-this ' ] as $ tagName ) {
422
+ foreach ($ phpDocNode ->getParamClosureThisTagValues ($ tagName ) as $ tagValue ) {
423
+ $ parameterName = substr ($ tagValue ->parameterName , 1 );
424
+ $ closureThisTypes [$ parameterName ] = new ParamClosureThisTag ($ this ->typeNodeResolver ->resolve ($ tagValue ->type , $ nameScope ));
425
+ }
426
+ }
427
+
428
+ return $ closureThisTypes ;
429
+ }
430
+
460
431
public function resolveReturnTag (PhpDocNode $ phpDocNode , NameScope $ nameScope ): ?ReturnTag
461
432
{
462
433
$ resolved = null ;
0 commit comments