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

Improve QueryResultDynamicReturnTypeExtension #520

Open
wants to merge 15 commits into
base: 1.3.x
Choose a base branch
from

Conversation

VincentLanglet
Copy link
Contributor

Same as #453 (comment)

With the commit 1b0a1b0

I changed the strategy to be easily accepted and then easier to merge:

  • If I can precisely infer the type, I return the type
  • If not, I rely on the default return type rather than returning an half-precise type like array<mixed> => This way we have the same behavior than before and people doesn't get error moving from level 9 to 7-8.

@ondrejmirtes
Copy link
Member

Alright, I'm gonna look at this again after #506 is merged.

@VincentLanglet VincentLanglet marked this pull request as ready for review April 18, 2024 12:54
@VincentLanglet
Copy link
Contributor Author

From #453 (comment)

Real world project number 2: 21 new errors, some queries use getScalarResult and getResult(AbstractQuery::HYDRATE_SCALAR). In these cases the inferred type is mixed which should be improved. Example query (anonymized):

 $qb = $this->createQueryBuilder('a');
 $result = $qb
            ->select('a.one, a.two, a.three')
            ->andWhere($qb->expr()->in('a.four', $four))
            ->orderBy('a.date', 'ASC')
            ->getQuery()
            ->getResult(AbstractQuery::HYDRATE_SCALAR);

This is fixed by the commit 1b0a1b0

Real world project number 1: 48 new errors, most are "Casting to int something that's already int.". A few real bugs found. But the PR is not currently usable because COUNT(pr.id) AS count as inferred as int<0, max>|numeric-string which will be solved by #506.

I'm curious about this "bug" because COUNT(pr.id) AS count is supposed to be inferred as __benevolent(int<0, max>|numeric-string) in this PR. It's tested here:
https://github.com/phpstan/phpstan-doctrine/pull/520/files#diff-28394df5dba3e85fe86f9c8d9b05d6087fe897d0efa1d0c0ad3533a1f0252b99R381-R413

Did you kept any example of query with your issue @ondrejmirtes ?

@ondrejmirtes
Copy link
Member

I'm sorry, I want to wait for #506 to be finished before trying #520 again.

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

Successfully merging this pull request may close these issues.

None yet

2 participants