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

Generic phpdoc template incorrect #620

Closed
vitkutny opened this issue Aug 16, 2024 · 5 comments
Closed

Generic phpdoc template incorrect #620

vitkutny opened this issue Aug 16, 2024 · 5 comments

Comments

@vitkutny
Copy link

vitkutny commented Aug 16, 2024

Source code from Doctrine ORM:

namespace Doctrine\ORM;

interface EntityManagerInterface extends ObjectManager
{
    /**
     * {@inheritDoc}
     *
     * @psalm-param class-string<T> $className
     *
     * @psalm-return EntityRepository<T>
     *
     * @template T of object
     */
    public function getRepository($className);

Method call:

$this->entityManager->getRepository(MyEntity::class)->findBy($criteria);

Actual results:

Call to unknown method: MyEntity::findBy() – PHP(PHP0418)

Expected result: no errors – expecting getRepository return value to by of type EntityRepository<MyEntity> instead of MyEntity itself

@jakubmisek
Copy link
Member

Thank you. I'm trying doctrine/orm v2.18:

image

and it works as expected;

Can you check where the editor guesses the wrong type exactly? Or create a complete small test case. Do you have the correct function signature in tooltip?

image

@vitkutny
Copy link
Author

Maybe it works differently in VS code <=> VS – if your screenshots are from VS ? I am using VS code extension. Tried upgrading doctrine/orm and reinstalling php extension which didnt help.

Screenshot 2024-08-17 at 10 12 32 Screenshot 2024-08-17 at 10 08 04

@jakubmisek
Copy link
Member

Isn't there an "ide_helper" with some incorrectly generated stubs?

@vitkutny
Copy link
Author

vitkutny commented Aug 17, 2024

Found the source of this issue! We are using nettrine/orm which integrates Doctrine into Nette framework https://github.com/contributte/doctrine-orm

There is phpstorm metadata file .phpstorm.meta.php – everytihing works correctly when deleted https://github.com/contributte/doctrine-orm/blob/master/.phpstorm.meta.php

It was added for phpstorm to be able to detect dynamic return type, but looking at the file its wrong that the definition of find and getRepository is the same. Dont know if this is working correctly in phpstorm, or getRepository meta should be deleted / edited

contributte/doctrine-orm@b6e683a

file was created based on PR contributte/doctrine-orm#49

@jakubmisek
Copy link
Member

Awesome! I thought it would be something like this.

It seems the .phpstorm.meta.php file is simply incorrect, and it does not work in PhpStorm either (PhpStorm is just much quieter about errors, so people may not notice). I suggest reporting the issue to them as well.

vitkutny added a commit to vitkutny/doctrine-orm that referenced this issue Aug 20, 2024
Overrides for getRepository are invalid – it overrides returned type from `@returns Collection<T>` to returning the entity directly `@returns T`

See DEVSENSE/phptools-docs#620
vitkutny added a commit to vitkutny/doctrine-orm that referenced this issue Aug 20, 2024
Overrides for getRepository are invalid – it overrides returned type from `@returns Collection<T>` to returning the entity directly `@returns T`

See DEVSENSE/phptools-docs#620
f3l1x pushed a commit to contributte/doctrine-orm that referenced this issue Aug 20, 2024
Overrides for getRepository are invalid – it overrides returned type from `@returns Collection<T>` to returning the entity directly `@returns T`

See DEVSENSE/phptools-docs#620
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

2 participants