Skip to content

Repository type not matched when set to a property #21

@soullivaneuh

Description

@soullivaneuh

In a nutshell, this PHP class:

use Doctrine\ORM\Decorator\EntityManagerDecorator;
use PowerDNSBundle\Doctrine\ORM\PowerDNSEntityManager;
use PowerDNSBundle\Entity\PowerDNSDomain;

class DnsManager extends EntityManagerDecorator
{
    /**
     * @var ObjectRepository
     */
    private $domainRepository;

    public function __construct(PowerDNSEntityManager $wrapped)
    {
        parent::__construct($wrapped);

        $this->domainRepository = $this->getRepository(PowerDNSDomain::class);
    }

    public function addDomainIfNotExists($name, User $user, $ipV4 = null, $ipV6 = null, $checkDNS = true)
    {
        $nameCanonical = \idn_to_ascii($name);
        $domain = $this->domainRepository->findOneBy(['name' => $nameCanonical]);

        if (!$domain) {
            $domain = new PowerDNSDomain();
            $domain->setName($name);
            $domain->setOwnerId($user->getId());
            $this->saveDomain($domain, $ipV4, $ipV6, $checkDNS);
        }

        return $domain;
    }
}

Produces:

 ------ ---------------------------------------------------------------------- 
  Line   src/AppBundle/Manager/DnsManager.php                                  
 ------ ---------------------------------------------------------------------- 
  170    Method AppBundle\Manager\DnsManager::addDomainIfNotExists() should    
         return PowerDNSBundle\Entity\PowerDNSDomain but returns object.       

Replacing the line by $domain = $this->getRepository(PowerDNSDomain::class)->findOneBy(['name' => $nameCanonical]); directly "solve" the issue.

It seems the property assignation of repositories is not handled by the extension.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions