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

Template QueryBuilder #117

Open
DanielBadura opened this issue Jun 17, 2022 · 1 comment
Open

Template QueryBuilder #117

DanielBadura opened this issue Jun 17, 2022 · 1 comment

Comments

@DanielBadura
Copy link

DanielBadura commented Jun 17, 2022

I get this error:

ERROR: MixedReturnTypeCoercion - ProfileRepository.php:22:16 - The declared return type 'array<array-key, Profile>' for ProfileRepository::getProfiles is more specific than the inferred return type 'list<mixed>' (see https://psalm.dev/197)
     * @return array<Profile>

With this Repo (simple example of using QueryBuilder):

/**
 * @template-extends ServiceEntityRepository<Profile>
 */
class ProfileRepository extends ServiceEntityRepository
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, Profile::class);
    }

    /**
     * @return array<Profile>
     */
    public function getProfiles(): array
    {
        return $this->createQueryBuilder('p')->getQuery()->getResult();
    }
}

So I'm questioning myself: Should EntityRepository->createQueryBuilder() return a Query with the templated type Profile instead of mixed? Right now Query can be templated thanks to this plugin but the QueryBuilder cannot pass this information to the Query right now so it returns mixed. But if we maybe add the template annotation to the QueryBuilder we could pass it to Query. I tried to update the stubs for QueryBuilder but this was of course not sufficient. So i tried to update the plugin with an hook like the Collection hook already provided but failed to get it working. So first, i wanted to check if this route is the right before putting more work into it. So what do you think?

@DanielBadura
Copy link
Author

Well i realised that i just needed to update also the EntityRepository stub. So providing soon a PR 😅

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 a pull request may close this issue.

1 participant