DoctrineTransactionFactory::createTransaction()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

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