diff --git a/src/Type/Constant/ConstantArrayType.php b/src/Type/Constant/ConstantArrayType.php index 1514781d0f..9a7e314d2c 100644 --- a/src/Type/Constant/ConstantArrayType.php +++ b/src/Type/Constant/ConstantArrayType.php @@ -483,6 +483,7 @@ public function getCallableParametersAcceptors(ClassMemberAccessAnswerer $scope) } $method = $typeAndMethodName->getType() + ->getObjectTypeOrClassStringObjectType() ->getMethod($typeAndMethodName->getMethod(), $scope); if (!$scope->canCallMethod($method)) { @@ -567,7 +568,7 @@ public function findTypeAndMethodNames(): array $has = $has->and(TrinaryLogic::createMaybe()); } - $typeAndMethods[] = ConstantArrayTypeAndMethod::createConcrete($type, $method->getValue(), $has); + $typeAndMethods[] = ConstantArrayTypeAndMethod::createConcrete($classOrObject, $method->getValue(), $has); } return $typeAndMethods; diff --git a/tests/PHPStan/Type/Constant/ConstantArrayTypeTest.php b/tests/PHPStan/Type/Constant/ConstantArrayTypeTest.php index b047b86a69..5697dee6b2 100644 --- a/tests/PHPStan/Type/Constant/ConstantArrayTypeTest.php +++ b/tests/PHPStan/Type/Constant/ConstantArrayTypeTest.php @@ -1051,4 +1051,34 @@ public function testValuesArray(ConstantArrayType $type, ConstantArrayType $expe $this->assertSame($expectedType->getNextAutoIndexes(), $actualType->getNextAutoIndexes()); } + public function testFindTypeAndMethodNames(): void + { + $classStringArray = new ConstantArrayType([ + new ConstantIntegerType(0), + new ConstantIntegerType(1), + ], [ + new ConstantStringType(Closure::class, true), + new ConstantStringType('bind'), + ]); + $objectArray = new ConstantArrayType([ + new ConstantIntegerType(0), + new ConstantIntegerType(1), + ], [ + new ObjectType(Closure::class, null, $this->createReflectionProvider()->getClass(Closure::class)), + new ConstantStringType('bind'), + ]); + + $classStringResult = $classStringArray->findTypeAndMethodNames(); + $objectResult = $objectArray->findTypeAndMethodNames(); + + $this->assertCount(1, $classStringResult); + $this->assertCount(1, $objectResult); + $this->assertInstanceOf(ConstantStringType::class, $classStringResult[0]->getType()); + $this->assertInstanceOf(ObjectType::class, $objectResult[0]->getType()); + $this->assertSame('bind', $classStringResult[0]->getMethod()); + $this->assertSame('bind', $objectResult[0]->getMethod()); + $this->assertSame(TrinaryLogic::createYes(), $classStringResult[0]->getCertainty()); + $this->assertSame(TrinaryLogic::createYes(), $objectResult[0]->getCertainty()); + } + }