Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return of mixed in $this->createQueryBuilder()->getQuery()->getResult() when alias is ev or event #608

Open
ruudk opened this issue Sep 12, 2024 · 9 comments

Comments

@ruudk
Copy link
Contributor

ruudk commented Sep 12, 2024

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?

@janedbal
Copy link
Contributor

Replicated: #609

@ruudk
Copy link
Contributor Author

ruudk commented Sep 12, 2024

I was just using Xdebug to find the issue:

It's throwing here:

if ($value->isClassStringType()->yes() && count($value->getClassStringObjectType()->getObjectClassNames()) === 1) {
/** @var class-string $className */
$className = $value->getClassStringObjectType()->getObjectClassNames()[0];
if ($this->objectMetadataResolver->isTransient($className)) {
throw new DynamicQueryBuilderArgumentException();
}

@ruudk
Copy link
Contributor Author

ruudk commented Sep 12, 2024

It seems that $className is the alias ev now:
Screenshot 2024-09-12 at 16 39 15@2x

@ruudk
Copy link
Contributor Author

ruudk commented Sep 12, 2024

Interesting:
Screenshot 2024-09-12 at 16 40 16@2x
It thinks this ConstantStringType is a ClassStringType

@ruudk
Copy link
Contributor Author

ruudk commented Sep 12, 2024

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

@janedbal
Copy link
Contributor

janedbal commented Sep 12, 2024

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

image

@janedbal
Copy link
Contributor

@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.

@ondrejmirtes
Copy link
Member

Yeah, it should throw only in arguments that expect class-string. Which is reasonable to assume in Doctrine that it must not be transient.

@janedbal
Copy link
Contributor

I believe it would be the same issue as #566

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants