Skip to content

Commit 13f6406

Browse files
authored
ConstantArrayType: fix returned ConstantArrayTypeAndMethod
1 parent 7807722 commit 13f6406

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

Diff for: src/Type/Constant/ConstantArrayType.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ public function getCallableParametersAcceptors(ClassMemberAccessAnswerer $scope)
499499
}
500500

501501
$method = $typeAndMethodName->getType()
502+
->getObjectTypeOrClassStringObjectType()
502503
->getMethod($typeAndMethodName->getMethod(), $scope);
503504

504505
if (!$scope->canCallMethod($method)) {
@@ -583,7 +584,7 @@ public function findTypeAndMethodNames(): array
583584
$has = $has->and(TrinaryLogic::createMaybe());
584585
}
585586

586-
$typeAndMethods[] = ConstantArrayTypeAndMethod::createConcrete($type, $method->getValue(), $has);
587+
$typeAndMethods[] = ConstantArrayTypeAndMethod::createConcrete($classOrObject, $method->getValue(), $has);
587588
}
588589

589590
return $typeAndMethods;

Diff for: tests/PHPStan/Type/Constant/ConstantArrayTypeTest.php

+30
Original file line numberDiff line numberDiff line change
@@ -1051,4 +1051,34 @@ public function testValuesArray(ConstantArrayType $type, ConstantArrayType $expe
10511051
$this->assertSame($expectedType->getNextAutoIndexes(), $actualType->getNextAutoIndexes());
10521052
}
10531053

1054+
public function testFindTypeAndMethodNames(): void
1055+
{
1056+
$classStringArray = new ConstantArrayType([
1057+
new ConstantIntegerType(0),
1058+
new ConstantIntegerType(1),
1059+
], [
1060+
new ConstantStringType(Closure::class, true),
1061+
new ConstantStringType('bind'),
1062+
]);
1063+
$objectArray = new ConstantArrayType([
1064+
new ConstantIntegerType(0),
1065+
new ConstantIntegerType(1),
1066+
], [
1067+
new ObjectType(Closure::class, null, $this->createReflectionProvider()->getClass(Closure::class)),
1068+
new ConstantStringType('bind'),
1069+
]);
1070+
1071+
$classStringResult = $classStringArray->findTypeAndMethodNames();
1072+
$objectResult = $objectArray->findTypeAndMethodNames();
1073+
1074+
$this->assertCount(1, $classStringResult);
1075+
$this->assertCount(1, $objectResult);
1076+
$this->assertInstanceOf(ConstantStringType::class, $classStringResult[0]->getType());
1077+
$this->assertInstanceOf(ObjectType::class, $objectResult[0]->getType());
1078+
$this->assertSame('bind', $classStringResult[0]->getMethod());
1079+
$this->assertSame('bind', $objectResult[0]->getMethod());
1080+
$this->assertSame(TrinaryLogic::createYes(), $classStringResult[0]->getCertainty());
1081+
$this->assertSame(TrinaryLogic::createYes(), $objectResult[0]->getCertainty());
1082+
}
1083+
10541084
}

0 commit comments

Comments
 (0)