ReopeningEntityManager   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A open() 0 4 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Shlinkio\Shlink\Common\Doctrine;
6
7
use Closure;
8
use Doctrine\ORM\Decorator\EntityManagerDecorator;
9
10
/**
11
 * @final
12
 */
13
class ReopeningEntityManager extends EntityManagerDecorator implements ReopeningEntityManagerInterface
14
{
15
    private Closure $createEm;
16
17 3
    public function __construct(callable $createEm)
18
    {
19 3
        parent::__construct($createEm());
20 3
        $this->createEm = Closure::fromCallable($createEm);
21
    }
22
23 2
    public function open(): void
24
    {
25 2
        if (! $this->wrapped->isOpen()) {
26 1
            $this->wrapped = ($this->createEm)();
27
        }
28
    }
29
}
30