88use PHPStan \Analyser \Scope ;
99use PHPStan \Reflection \MethodReflection ;
1010use PHPStan \Reflection \ParametersAcceptorSelector ;
11- use PHPStan \Type \Constant \ConstantStringType ;
1211use PHPStan \Type \DynamicMethodReturnTypeExtension ;
1312use PHPStan \Type \MixedType ;
1413use PHPStan \Type \Type ;
1514
16- class GetRepositoryDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension
15+ class GetRepositoryDynamicReturnTypeExtension implements
16+ DynamicMethodReturnTypeExtension
1717{
18- /** @var string */
19- private $ sdkClientClass ;
18+ private string $ sdkClientClass ;
2019
21- /** @var ObjectMetadataResolver */
22- private $ metadataResolver ;
20+ private ObjectMetadataResolver $ metadataResolver ;
2321
2422 public function __construct (
2523 string $ sdkClientClass ,
26- ObjectMetadataResolver $ metadataResolver
24+ ObjectMetadataResolver $ metadataResolver,
2725 ) {
26+ /** @var class-string $sdkClientClass */
2827 $ this ->sdkClientClass = $ sdkClientClass ;
2928 $ this ->metadataResolver = $ metadataResolver ;
3029 }
3130
3231 public function getClass (): string
3332 {
33+ /** @var class-string */
3434 return $ this ->sdkClientClass ;
3535 }
3636
@@ -42,20 +42,28 @@ public function isMethodSupported(MethodReflection $methodReflection): bool
4242 public function getTypeFromMethodCall (
4343 MethodReflection $ methodReflection ,
4444 MethodCall $ methodCall ,
45- Scope $ scope
45+ Scope $ scope,
4646 ): Type {
47- if (0 === count ($ methodCall ->args )) {
48- return ParametersAcceptorSelector::selectSingle (
49- $ methodReflection ->getVariants ()
47+ $ args = $ methodCall ->getArgs ();
48+ if (0 === count ($ args )) {
49+ return ParametersAcceptorSelector::selectFromArgs (
50+ $ scope ,
51+ $ args ,
52+ $ methodReflection ->getVariants (),
5053 )->getReturnType ();
5154 }
52- $ argType = $ scope ->getType ($ methodCall ->args [0 ]->value );
53- if (!$ argType instanceof ConstantStringType) {
55+ $ argType = $ scope ->getType ($ args [0 ]->value );
56+ $ constantStrings = $ argType ->getConstantStrings ();
57+ if (count ($ constantStrings ) === 0 ) {
5458 return new MixedType ();
5559 }
56- $ objectName = $ argType ->getValue ();
57- $ className = $ this ->metadataResolver ->resolveClassnameForKey ($ objectName );
58- $ repositoryClass = $ this ->metadataResolver ->getRepositoryClass ($ className );
60+ $ objectName = $ constantStrings [0 ]->getValue ();
61+ $ className = $ this ->metadataResolver ->resolveClassnameForKey (
62+ $ objectName ,
63+ );
64+ $ repositoryClass = $ this ->metadataResolver ->getRepositoryClass (
65+ $ className ,
66+ );
5967
6068 return new ObjectRepositoryType ($ className , $ repositoryClass );
6169 }
0 commit comments