DoctrineFacade   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 10
c 2
b 0
f 0
dl 0
loc 34
ccs 12
cts 12
cp 1
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getDefaultManager() 0 3 1
A getManager() 0 7 2
A __construct() 0 3 1
A managerPool() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 *  This file is part of the Micro framework package.
7
 *
8
 *  (c) Stanislau Komar <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace Micro\Plugin\Doctrine;
15
16
use Doctrine\DBAL\Exception;
17
use Doctrine\ORM\EntityManagerInterface;
18
use Doctrine\ORM\Exception\MissingMappingDriverImplementation;
19
use Micro\Plugin\Doctrine\Business\Pool\EntityManagerPoolFactoryInterface;
20
use Micro\Plugin\Doctrine\Business\Pool\EntityManagerPoolInterface;
21
22
class DoctrineFacade implements DoctrineFacadeInterface
23
{
24
    private EntityManagerPoolInterface|null $managerPool;
25
26 1
    public function __construct(private readonly EntityManagerPoolFactoryInterface $managerPoolFactory)
27
    {
28 1
        $this->managerPool = null;
29
    }
30
31 1
    public function getManager(string $name = null): EntityManagerInterface
32
    {
33 1
        if (!$name) {
34 1
            $name = DoctrinePluginConfigurationInterface::MANAGER_DEFAULT;
35
        }
36
37 1
        return $this->managerPool()->getManager($name);
38
    }
39
40
    /**
41
     * @throws MissingMappingDriverImplementation
42
     * @throws Exception
43
     */
44 1
    public function getDefaultManager(): EntityManagerInterface
45
    {
46 1
        return $this->getManager();
47
    }
48
49 1
    protected function managerPool(): EntityManagerPoolInterface
50
    {
51 1
        if (null === $this->managerPool) {
52 1
            $this->managerPool = $this->managerPoolFactory->create();
53
        }
54
55 1
        return $this->managerPool;
56
    }
57
}
58