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

PropertyNotSetInConstructor: Property Doctrine\ORM\EntityRepository::$_entityName is not defined in constructor of Repository and in any methods called in the constructor #30

Closed
ruudk opened this issue Oct 23, 2019 · 6 comments

Comments

@ruudk
Copy link

ruudk commented Oct 23, 2019

Thanks for this plugin. It removes a lot of false errors from my codebase ❤️

I wonder if we can also fix this error:

INFO: PropertyNotSetInConstructor - src/Infrastructure/Persistence/Doctrine/Repository/DoctrineSettlementRepository.php:15:13 - Property Doctrine\ORM\EntityRepository::$_entityName is not defined in constructor of Infrastructure\Persistence\Doctrine\Repository\DoctrineSettlementRepository and in any methods called in the constructor
final class DoctrineSettlementRepository extends AbstractServiceEntityRepository implements SettlementRepository

code:

final class DoctrineSettlementRepository extends AbstractServiceEntityRepository implements SettlementRepository
{
    public function __construct(RegistryInterface $registry)
    {
        parent::__construct($registry, Settlement::class);
    }
@ruudk
Copy link
Author

ruudk commented Nov 4, 2019

@weirdan do you have tips how to approach this? Maybe I can create a PR to solve it.

@ruudk
Copy link
Author

ruudk commented Nov 4, 2019

This solves it: #31

@weirdan
Copy link
Member

weirdan commented Nov 4, 2019

@ruudk do you have a self-contained reproducer for this (one that does not rely on your internal classes)? I've seen this error before, but never managed to succinctly reproduce it. As far as I recon it's a Psalm bug, and a way to reproduce would be the first step to fix it there.

@ruudk
Copy link
Author

ruudk commented Nov 5, 2019

use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Symfony\Bridge\Doctrine\RegistryInterface;

/**
 * @template T
 * @template-extends ServiceEntityRepository<T>
 */
abstract class AbstractServiceEntityRepository extends ServiceEntityRepository
{
    /**
     * @var RegistryInterface
     */
    private $registry;

    public function __construct(RegistryInterface $registry, string $entityClass)
    {
        parent::__construct($registry, $entityClass);

        $this->registry = $registry;
    }
}

class Settlement {}

final class DoctrineSettlementRepository extends AbstractServiceEntityRepository
{
    public function __construct(RegistryInterface $registry)
    {
        parent::__construct($registry, Settlement::class);
    }
}

Does this work?

@weirdan
Copy link
Member

weirdan commented Nov 10, 2019

@ruudk
Copy link
Author

ruudk commented Nov 10, 2019

Thanks

@ruudk ruudk closed this as completed Nov 10, 2019
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