@@ -503,23 +503,46 @@ public function getCallableParametersAcceptors(ClassMemberAccessAnswerer $scope)
503503 return $ acceptors ;
504504 }
505505
506- /** @deprecated Use findTypeAndMethodNames() instead */
507- public function findTypeAndMethodName (): ?ConstantArrayTypeAndMethod
506+ /**
507+ * @return array{Type, Type}|array{}
508+ */
509+ private function getClassOrObjectAndMethods (): array
508510 {
509511 if (count ($ this ->keyTypes ) !== 2 ) {
510- return null ;
512+ return [] ;
511513 }
512514
513- if ($ this ->keyTypes [0 ]->isSuperTypeOf (new ConstantIntegerType (0 ))->no ()) {
514- return null ;
515+ $ classOrObject = null ;
516+ $ method = null ;
517+ foreach ($ this ->keyTypes as $ i => $ keyType ) {
518+ if ($ keyType ->isSuperTypeOf (new ConstantIntegerType (0 ))->yes ()) {
519+ $ classOrObject = $ this ->valueTypes [$ i ];
520+ continue ;
521+ }
522+
523+ if (!$ keyType ->isSuperTypeOf (new ConstantIntegerType (1 ))->yes ()) {
524+ continue ;
525+ }
526+
527+ $ method = $ this ->valueTypes [$ i ];
515528 }
516529
517- if ($ this -> keyTypes [ 1 ]-> isSuperTypeOf ( new ConstantIntegerType ( 1 ))-> no () ) {
518- return null ;
530+ if ($ classOrObject === null || $ method === null ) {
531+ return [] ;
519532 }
520533
521- [$ classOrObject , $ method ] = $ this ->valueTypes ;
534+ return [$ classOrObject , $ method ];
535+ }
536+
537+ /** @deprecated Use findTypeAndMethodNames() instead */
538+ public function findTypeAndMethodName (): ?ConstantArrayTypeAndMethod
539+ {
540+ $ callableArray = $ this ->getClassOrObjectAndMethods ();
541+ if ($ callableArray === []) {
542+ return null ;
543+ }
522544
545+ [$ classOrObject , $ method ] = $ callableArray ;
523546 if (!$ method instanceof ConstantStringType) {
524547 return ConstantArrayTypeAndMethod::createUnknown ();
525548 }
@@ -544,19 +567,12 @@ public function findTypeAndMethodName(): ?ConstantArrayTypeAndMethod
544567 /** @return ConstantArrayTypeAndMethod[] */
545568 public function findTypeAndMethodNames (): array
546569 {
547- if (count ($ this ->keyTypes ) !== 2 ) {
548- return [];
549- }
550-
551- if ($ this ->keyTypes [0 ]->isSuperTypeOf (new ConstantIntegerType (0 ))->no ()) {
552- return [];
553- }
554-
555- if ($ this ->keyTypes [1 ]->isSuperTypeOf (new ConstantIntegerType (1 ))->no ()) {
570+ $ callableArray = $ this ->getClassOrObjectAndMethods ();
571+ if ($ callableArray === []) {
556572 return [];
557573 }
558574
559- [$ classOrObject , $ methods ] = $ this -> valueTypes ;
575+ [$ classOrObject , $ methods ] = $ callableArray ;
560576 if (count ($ methods ->getConstantStrings ()) === 0 ) {
561577 return [ConstantArrayTypeAndMethod::createUnknown ()];
562578 }
0 commit comments