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

ManagerRegistryEntityManager   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 28
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setManagerName() 0 4 1
A getEntityManager() 0 9 2
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