phpstan-doctrine
phpstan-doctrine copied to clipboard
Return of mixed in `$this->createQueryBuilder()->getQuery()->getResult()` when alias is `ev` or `event`
I have no idea what this is, or what causes it.
// This all works: list<Event>
dumpType($this->createQueryBuilder('e')->getQuery()->getResult());
dumpType($this->createQueryBuilder('my_name')->getQuery()->getResult());
dumpType($this->createQueryBuilder('oo')->getQuery()->getResult());
dumpType($this->createQueryBuilder('abcdef')->getQuery()->getResult());
dumpType($this->createQueryBuilder('user')->getQuery()->getResult());
dumpType($this->createQueryBuilder('av')->getQuery()->getResult());
dumpType($this->createQueryBuilder('eve')->getQuery()->getResult());
dumpType($this->createQueryBuilder('even')->getQuery()->getResult());
// This returns: mixed
dumpType($this->createQueryBuilder('ev')->getQuery()->getResult());
dumpType($this->createQueryBuilder('event')->getQuery()->getResult());
I also tried this on a different entity repository, for an entity named differently: Type. There, it gives the same problem.
So what is the cause for ev and event to behave weird?
Replicated: https://github.com/phpstan/phpstan-doctrine/pull/609
I was just using Xdebug to find the issue:
It's throwing here: https://github.com/phpstan/phpstan-doctrine/blob/be66017631e5289e8a3bd8973e59781642da40fd/src/Type/Doctrine/ArgumentsProcessor.php#L61-L66
It seems that $className is the alias ev now:
Interesting:
It thinks this ConstantStringType is a ClassStringType
It seems that I have a class called ev and event. The last one makes sense, somewhere. But the first one? Interesting.
https://github.com/phpstan/phpstan-src/blob/5480d27383ffee399037c31d461c5a85344128ca/src/Type/Constant/ConstantStringType.php#L83-L92
Yes, because reflector see Event class as existing due to this stub:
- phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/SourceStubber/../../../../../jetbrains/phpstorm-stubs/event/event.stub
@ondrejmirtes added this condition here. I think we should be more careful where we do this check. Imo only in ->from(class-name) etc. Not in such a generic way for every argument.
Yeah, it should throw only in arguments that expect class-string. Which is reasonable to assume in Doctrine that it must not be transient.
I believe it would be the same issue as https://github.com/phpstan/phpstan-doctrine/issues/566