DoctrineFacade::managerPool()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
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