Passed
Push — master ( 7eee18...a4d1ec )
by Damien
02:57
created

TransactionManager   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 48
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 3 1
A getConfiguration() 0 3 1
A __construct() 0 6 1
A populate() 0 3 1
A selectStorageSpace() 0 3 1
1
<?php
2
3
namespace DH\DoctrineAuditBundle\Transaction;
4
5
use DH\DoctrineAuditBundle\Configuration;
6
use DH\DoctrineAuditBundle\Model\Transaction;
7
use Doctrine\ORM\EntityManagerInterface;
8
9
class TransactionManager
10
{
11
    /**
12
     * @var Configuration
13
     */
14
    private $configuration;
15
16
    /**
17
     * @var TransactionProcessor
18
     */
19
    private $processor;
20
21
    /**
22
     * @var TransactionHydrator
23
     */
24
    private $hydrator;
25
26
    public function __construct(Configuration $configuration)
27
    {
28
        $this->configuration = $configuration;
29
30
        $this->processor = new TransactionProcessor($configuration);
31
        $this->hydrator = new TransactionHydrator($configuration);
32
    }
33
34
    public function getConfiguration(): Configuration
35
    {
36
        return $this->configuration;
37
    }
38
39
    public function populate(Transaction $transaction): void
40
    {
41
        $this->hydrator->hydrate($transaction);
42
    }
43
44
    public function process(Transaction $transaction): void
45
    {
46
        $this->processor->process($transaction);
47
    }
48
49
    /**
50
     * @param EntityManagerInterface $em
51
     *
52
     * @return EntityManagerInterface
53
     */
54
    public function selectStorageSpace(EntityManagerInterface $em): EntityManagerInterface
55
    {
56
        return $this->configuration->getEntityManager() ?? $em;
57
    }
58
}
59