Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPStan is not interpreting a Symfony EntityRepository as a generic

I'm having trouble making sense of this PHPStan error. PHPStan is saying I need to provide the class string of an EntityRepository of an object. I am providing the class string of a ServiceEntityRepository (which extends EntityRepository) of class "Schedule".

Error

Parameter $repositoryClass of attribute class Doctrine\ORM\Mapping\Entity constructor expects class-string<Doctrine\ORM\EntityRepository<T of object>>|null, 'App\Repository\ScheduleRepository' given.

Code

Here is the offending code:

namespace App\Entity\Schedule;

use App\Repository\ScheduleRepository;

#[ORM\Entity(repositoryClass: ScheduleRepository::class)]
class Schedule implements JsonSerializable
{
    // ...

And the repository class referenced:

namespace App\Repository;

use App\Entity\Schedule\Schedule;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;

/*
 * @extends ServiceEntityRepository<Schedule>
 */
class ScheduleRepository extends ServiceEntityRepository
{
    // ...

(Note: ServiceEntityRepository extends EntityRepository.)

like image 931
amacrobert Avatar asked Nov 15 '25 17:11

amacrobert


1 Answers

This was a bug in phpstan.

Solution: Upgrade phpstan to 1.6.8.

like image 129
amacrobert Avatar answered Nov 17 '25 08:11

amacrobert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!