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 a generic array in Query #115

Merged
merged 2 commits into from
Apr 16, 2022
Merged

Return a generic array in Query #115

merged 2 commits into from
Apr 16, 2022

Conversation

2e3s
Copy link
Contributor

@2e3s 2e3s commented Apr 14, 2022

This may not be a list, it may be an indexed array. Example:
https://github.com/doctrine/orm/blob/bfed8cb6ed448f4ab1ea3fff06e4d6c44439e4ef/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php#L491

This is a potential error like

ERROR: RedundantFunctionCallGivenDocblockType - src/*** - The call to array_values is unnecessary given the list docblock type list<mixed> (see https://psalm.dev/281)
        return array_values($result);

@orklah
Copy link
Collaborator

orklah commented Apr 15, 2022

Can the type of the index be determined somehow?

@2e3s
Copy link
Contributor Author

2e3s commented Apr 16, 2022

The type is taken from DB, it's a type of the field. It's possible to parametrize Query with this key as a template, not sure if it's worth it.

@orklah orklah merged commit 40c2ccc into psalm:2.x Apr 16, 2022
@orklah
Copy link
Collaborator

orklah commented Apr 16, 2022

Thanks!

@2e3s 2e3s deleted the patch-1 branch April 16, 2022 20:18
AndrolGenhald added a commit to AndrolGenhald/psalm-plugin-doctrine that referenced this pull request Jul 20, 2022
AndrolGenhald added a commit to AndrolGenhald/psalm-plugin-doctrine that referenced this pull request Jul 20, 2022
AndrolGenhald added a commit to AndrolGenhald/psalm-plugin-doctrine that referenced this pull request Jul 20, 2022
orklah added a commit that referenced this pull request Jul 21, 2022
…return-type

Fix templates on QueryBuilder::getQuery return type (broken by #115).
@VincentLanglet
Copy link
Contributor

Is the commit a3a972c really useful ?

Changing the generic signature is kinda a BC break for all static analysis users. And it create conflict with others tools like phpstan (as showed here phpstan/phpstan-doctrine#377). This shouldn't be done so easily.

I dunno how it works but array can be written with one template array<mixed> and two templates array<array-key, mixed>. Isn't possible to do the same in such situation in the futur ?

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

4 participants