DoctrineTransactionFactory::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace App\Infrastructure\Doctrine\Transactions;
4
5
use App\Infrastructure\Doctrine\DoctrineEntityManagerAware;
6
use App\Infrastructure\Transactions\TransactionFactoryInterface;
7
use App\Infrastructure\Transactions\TransactionInterface;
8
use Doctrine\Persistence\ManagerRegistry;
9
10
abstract class DoctrineTransactionFactory extends DoctrineEntityManagerAware implements TransactionFactoryInterface
11
{
12
13 16
    public function __construct(
14
        ManagerRegistry $managerRegistry,
15
    )
16
    {
17 16
        parent::__construct($managerRegistry);
18 16
    }
19
20 15
    /**
21
     * Resets Entity Manager, if the current one is closed.
22 15
     *
23
     * @param $func
24 1
     * @return TransactionInterface
25
     */
26
   public function createTransaction($func): TransactionInterface
27
    {
28
        $em = $this->getEntityManager();
29
        if(!$em->isOpen()) {
30
            $em = $this->managerRegistry->resetManager($this->getManagerName());
31
        }
32
        return new DoctrineTransaction($em, $func);
33
    }
34
}