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

self::class in entity is interpreted in wrong context #512

Open
jlherren opened this issue Jan 8, 2024 · 3 comments · May be fixed by #513
Open

self::class in entity is interpreted in wrong context #512

jlherren opened this issue Jan 8, 2024 · 3 comments · May be fixed by #513

Comments

@jlherren
Copy link

jlherren commented Jan 8, 2024

With this entity:

#[Entity]
class Person {
    #[Id]
    #[Column(type: "integer")]
    public int $id;

    public static function getQb(EntityManager $em): QueryBuilder {
        return $em->createQueryBuilder()
                  ->select('p')
                  ->from(self::class, 'p');
    }
}

And this code:

class Test {
    public static function test(EntityManager $em): void {
        Person::getQb($em)->getQuery()->getResult();
    }
}

I get the following error:

 -- --------------------------------------------------------------------------------------------------------------------
     Error
 -- --------------------------------------------------------------------------------------------------------------------
     Internal error: Internal error: Class "App\Test" is not a valid entity or mapped super class. while analysing file
     C:\Projekte\TestProjects\PhpstanDoctrine\src\Test.php
     Run PHPStan with -v option and post the stack trace to:
     https://github.com/phpstan/phpstan/issues/new?template=Bug_report.yaml
     Child process error (exit code 1):
 -- --------------------------------------------------------------------------------------------------------------------

If I replace self::class with Person::class, it works as expected. It seems that self is being understood to be Test, when in fact it refers to Person. I can provide a fuller reproduction example if desired. This seems to have gone broken in a recent release.

@janedbal
Copy link
Contributor

janedbal commented Jan 8, 2024

Providing a failing test would be the best, thanks

jlherren added a commit to jlherren/phpstan-doctrine that referenced this issue Jan 8, 2024
@jlherren
Copy link
Author

jlherren commented Jan 8, 2024

See 1.4.x...jlherren:phpstan-doctrine:bug-512

Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'Doctrine\ORM\Query<null, QueryResult\Entities\One>'
+'Doctrine\ORM\Query<mixed, mixed>'
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'list<QueryResult\Entities\One>'
+'mixed'

@janedbal
Copy link
Contributor

janedbal commented Jan 9, 2024

This seems to have gone broken in a recent release.

The underlying issue is there for a long time, 1.3.53 just extended the places where such feature is used so it poped up.

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.

2 participants