Completed
Pull Request — master (#1023)
by Asmir
02:45 queued 16s
created

ManagerRegistryEntityManager::getEntityManager()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Migrations\Configuration\EntityManager;
6
7
use Doctrine\ORM\EntityManagerInterface;
8
use Doctrine\Persistence\ManagerRegistry;
9
use RuntimeException;
10
11
final class ManagerRegistryEntityManager implements EntityManagerLoader
12
{
13
    /** @var ManagerRegistry */
14
    private $registry;
15
16
    /** @var string|null */
17
    private $managerName;
18
19
    public function __construct(ManagerRegistry $managerRegistry)
20
    {
21
        $this->registry = $managerRegistry;
22
    }
23
24
    public function setManagerName(?string $managerName) : void
25
    {
26
        $this->managerName = $managerName;
27
    }
28
29
    public function getEntityManager() : EntityManagerInterface
30
    {
31
        $em = $this->registry->getManager($this->managerName);
32
        if (! $em instanceof EntityManagerInterface) {
33
            throw new RuntimeException('The returned  must be @todo');
34
        }
35
36
        return $em;
37
    }
38
}
39