Could you please add support for the @phpstan-assert annotation for narrowing down types? It greatly helps with custom assertions.
See the "isObjectOfClass" example here: https://phpstan.org/writing-php-code/narrowing-types
roben Good idea, will be added.
For now, we have @trace annotation to check the types of expressions in inlay hint:
@trace
/** @trace $expression */
Thanks! But @assert differs a bit from @trace as it changes the type, that's whats important for us. It's more like a type cast than an assertion from a programmers view. But it is also different from @var because you can apply it to method parameters which then applies to any variable being passed into this method.
@assert
@var
Oh, I just noticed the isObjectOfClass() example uses @phpstan-assert-if-true. That's mostly the same but only applies if the return value of the method is true. For us, @phpstan-assert is more important, but maybe it is reasonable to implement all variants.
isObjectOfClass()
@phpstan-assert-if-true
true
@phpstan-assert
I see, thanks! That will take some time to implement :)
progress
phpstan-assert
!
$this->getName()
Awesome, thanks!