phpstan-doctrine
phpstan-doctrine copied to clipboard
self::class in entity is interpreted in wrong context
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.
I'm running into this now as well. Oddly, it didn't happen for me until after I added additional collections and starting messing with default frontmatter. I can't tell what caused it to start.
It only happens on Edit. Creation of new items lands them where they're supposed to go.
This is a breaking bug for me
2024-05-31 13:33:59 - NoMethodError - undefined method `to_api' for nil:NilClass:
/home/vcavallo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/jekyll-admin-0.11.1/lib/jekyll-admin/server/collections.rb:37:in `block (2 levels) in <class:Server>'
/home/vcavallo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/sinatra-2.2.4/lib/sinatra/base.rb:1697:in `call'
/home/vcavallo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/sinatra-2.2.4/lib/sinatra/base.rb:1697:in `block in compile!'
/home/vcavallo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/sinatra-2.2.4/lib/sinatra/base.rb:1030:in `block (3 levels) in route!'
/home/vcavallo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/sinatra-2.2.4/lib/sinatra/base.rb:1049:in `route_eval'
/home/vcavallo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/sinatra-2.2.4/lib/sinatra/base.rb:1030:in `block (2 levels) in route!'
/home/vcavallo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/sinatra-2.2.4/lib/sinatra/base.rb:1078:in `block in process_route'
/home/vcavallo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/sinatra-2.2.4/lib/sinatra/base.rb:1076:in `catch'
/home/vcavallo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/sinatra-2.2.4/lib/sinatra/base.rb:1076:in `process_route'
/home/vcavallo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/sinatra-2.2.4/lib/sinatra/base.rb:1028:in `block in route!'
/home/vcavallo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/sinatra-2.2.4/lib/sinatra/base.rb:1025:in `each'
/home/vcavallo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/sinatra-2.2.4/lib/sinatra/base.rb:1025:in `route!'
/home/vcavallo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/sinatra-2.2.4/lib/sinatra/base.rb:1147:in `block in dispatch!'
/home/vcavallo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/sinatra-2.2.4/lib/sinatra/base.rb:1119:in `block in invoke'
/home/vcavallo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/sinatra-2.2.4/lib/sinatra/base.rb:1119:in `catch'
/home/vcavallo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/sinatra-2.2.4/lib/sinatra/base.rb:1119:in `invoke'
/home/vcavallo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/sinatra-2.2.4/lib/sinatra/base.rb:1142:in `dispatch!'
/home/vcavallo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/sinatra-2.2.4/lib/sinatra/base.rb:956:in `block in call!'
/home/vcavallo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/sinatra-2.2.4/lib/sinatra/base.rb:1119:in `block in invoke'
/home/vcavallo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/sinatra-2.2.4/lib/sinatra/base.rb:1119:in `catch'
/home/vcavallo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/sinatra-2.2.4/lib/sinatra/base.rb:1119:in `invoke'
/home/vcavallo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/sinatra-2.2.4/lib/sinatra/base.rb:956:in `call!'
/home/vcavallo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/sinatra-2.2.4/lib/sinatra/base.rb:945:in `call'
/home/vcavallo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/rack-protection-2.2.4/lib/rack/protection/xss_header.rb:18:in `call'
/home/vcavallo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/rack-protection-2.2.4/lib/rack/protection/path_traversal.rb:16:in `call'
/home/vcavallo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/rack-protection-2.2.4/lib/rack/protection/json_csrf.rb:26:in `call'
/home/vcavallo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/rack-protection-2.2.4/lib/rack/protection/base.rb:50:in `call'
/home/vcavallo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/rack-protection-2.2.4/lib/rack/protection/base.rb:50:in `call'
/home/vcavallo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/rack-protection-2.2.4/lib/rack/protection/frame_options.rb:31:in `call'
/home/vcavallo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/rack-2.2.9/lib/rack/null_logger.rb:11:in `call'
/home/vcavallo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/rack-2.2.9/lib/rack/head.rb:12:in `call'
/home/vcavallo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/sinatra-2.2.4/lib/sinatra/base.rb:218:in `call'
/home/vcavallo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/sinatra-2.2.4/lib/sinatra/base.rb:2004:in `call'
/home/vcavallo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/sinatra-2.2.4/lib/sinatra/base.rb:1564:in `block in call'
/home/vcavallo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/sinatra-2.2.4/lib/sinatra/base.rb:1780:in `synchronize'
/home/vcavallo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/sinatra-2.2.4/lib/sinatra/base.rb:1564:in `call'
/home/vcavallo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/rack-2.2.9/lib/rack/handler/webrick.rb:95:in `service'
/home/vcavallo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/webrick-1.8.1/lib/webrick/httpserver.rb:140:in `service'
/home/vcavallo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/webrick-1.8.1/lib/webrick/httpserver.rb:96:in `run'
/home/vcavallo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/webrick-1.8.1/lib/webrick/server.rb:310:in `block in start_thread'