Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Type/Constant/ConstantArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ public function getCallableParametersAcceptors(ClassMemberAccessAnswerer $scope)
}

$method = $typeAndMethodName->getType()
->getObjectTypeOrClassStringObjectType()
->getMethod($typeAndMethodName->getMethod(), $scope);

if (!$scope->canCallMethod($method)) {
Expand Down Expand Up @@ -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;
Expand Down
30 changes: 30 additions & 0 deletions tests/PHPStan/Type/Constant/ConstantArrayTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the fix, this is still just ObjectType here.

$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());
}

}
Loading