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

Imperfect QueryBuilderType detection returned by other method call #499

Closed
janedbal opened this issue Nov 21, 2023 · 4 comments
Closed

Imperfect QueryBuilderType detection returned by other method call #499

janedbal opened this issue Nov 21, 2023 · 4 comments

Comments

@janedbal
Copy link
Contributor

See current behaviour:

class Foo {

    public function notWorking()
    {
        $queryBuilder = $this->createQueryBuilder();
        $queryBuilder->andWhere('1 = 1');

        $queryBuilder->getQuery()->getResult(); // mixed[]
    }

    public function working()
    {
        $queryBuilder = $this->createQueryBuilder()
              ->andWhere('1 = 1');

        $queryBuilder->getQuery()->getResult(); // list<Entity>
    }
}

This is because QueryBuilderMethodDynamicReturnTypeExtension detects only calls over QueryBuilder (second case) and optionally dives into the initial "other method" call to detect what happened there.

This could be fixed if I added some DynamicMethodReturnTypeExtension that is hooked to object and decided based on its return type (QueryBuilder) if OtherMethodQueryBuilderParser can be used to infer the enhanced QueryBuilderType. But no such thing is possible (hooking DynamicMethodReturnTypeExtension to any class).

Would you accept such PRs to accomplish this?

@janedbal
Copy link
Contributor Author

Added object hooking support in phpstan/phpstan-src#2761

@janedbal
Copy link
Contributor Author

POC in #500

@janedbal
Copy link
Contributor Author

This is not issue anymore, it solved by #500

Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant