Completed
Push — master ( 57a48c...37b82a )
by Alejandro
14s queued 13s
created

ReopeningEntityManager::open()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 0
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Shlinkio\Shlink\Common\Doctrine;
6
7
use Doctrine\ORM\Decorator\EntityManagerDecorator;
8
9
class ReopeningEntityManager extends EntityManagerDecorator
10
{
11
    /** @var callable */
12
    private $createEm;
13
14 3
    public function __construct(callable $createEm)
15
    {
16 3
        parent::__construct($createEm());
17 3
        $this->createEm = $createEm;
18
    }
19
20 2
    public function open(): void
21
    {
22 2
        if (! $this->wrapped->isOpen()) {
23 1
            $this->wrapped = ($this->createEm)();
24
        }
25
    }
26
}
27