Passed
Pull Request — master (#437)
by Alejandro
09:16
created

ReopeningEntityManager::merge()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
ccs 2
cts 2
cp 1
cc 1
nc 1
nop 1
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Shlinkio\Shlink\Common\Doctrine;
5
6
use Doctrine\ORM\Decorator\EntityManagerDecorator;
7
use Doctrine\ORM\EntityManagerInterface;
8
9
class ReopeningEntityManager extends EntityManagerDecorator
10
{
11
    /** @var callable */
12
    private $emFactory;
13
14 11
    public function __construct(EntityManagerInterface $wrapped, callable $emFactory)
15
    {
16 11
        parent::__construct($wrapped);
17 11
        $this->emFactory = $emFactory;
18
    }
19
20 10
    protected function getWrappedEntityManager(): EntityManagerInterface
21
    {
22 10
        if (! $this->wrapped->isOpen()) {
23 5
            $this->wrapped = ($this->emFactory)(
24 5
                $this->wrapped->getConnection(),
25 5
                $this->wrapped->getConfiguration(),
26 5
                $this->wrapped->getEventManager()
27
            );
28
        }
29
30 10
        return $this->wrapped;
31
    }
32
33 2
    public function flush($entity = null): void
34
    {
35 2
        $this->getWrappedEntityManager()->flush($entity);
36
    }
37
38 2
    public function persist($object): void
39
    {
40 2
        $this->getWrappedEntityManager()->persist($object);
41
    }
42
43 2
    public function remove($object): void
44
    {
45 2
        $this->getWrappedEntityManager()->remove($object);
46
    }
47
48 2
    public function refresh($object): void
49
    {
50 2
        $this->getWrappedEntityManager()->refresh($object);
51
    }
52
53 2
    public function merge($object)
54
    {
55 2
        return $this->getWrappedEntityManager()->merge($object);
56
    }
57
}
58