-
-
Notifications
You must be signed in to change notification settings - Fork 947
PHPStan loses type certainty outside of assertion blocks #5754
Copy link
Copy link
Closed
phpstan/phpstan-src
#1575Closed
Copy link
Labels
Milestone
Description
Bug report
On the last line, PHPStan is no longer able to understand that the queue is of the type returned by the context.
Code snippet that reproduces the problem
if ($context instanceof SnsQsContext) {
$this->queue = $context->createQueue('test');
} elseif ($context instanceof SqsContext) {
$this->queue = $context->createQueue('test');
} else {
throw new RuntimeException('nope');
}
$context->declareQueue($this->queue);Complete example: https://phpstan.org/r/f0317936-b04f-4c77-ab21-5f4997ba4479
Not sure if it's possible to fix this kind of edge case, the offending classes are in an external library so don't have much control over the Context/Queue just how we are implementing it. I can live with the Success variant, I just prefer the Fail variant.
Expected output
Fail class should pass but fails with:
Parameter #1 $name of method SnsQsContext::declareQueue() expects SnsQsQueue, SnsQsQueue|SqsQueue given.
Did PHPStan help you today? Did it make you happy in any way?
I love how much stuff PHPStan does pick up for me, and it's been a great help to ensuring our code quality and consistency remains high.
Reactions are currently unavailable