TransactionManager   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

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

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
    public const OPERATION_TYPE_INSERT = 'insert';
12
    public const OPERATION_TYPE_UPDATE = 'update';
13
    public const OPERATION_TYPE_REMOVE = 'remove';
14
    public const OPERATION_TYPE_ASSOCIATE = 'associate';
15
    public const OPERATION_TYPE_DISSOCIATE = 'dissociate';
16
17
    /**
18
     * @var Configuration
19
     */
20
    private $configuration;
21
22
    /**
23
     * @var TransactionProcessor
24
     */
25
    private $processor;
26
27
    /**
28
     * @var TransactionHydrator
29
     */
30
    private $hydrator;
31
32
    public function __construct(Configuration $configuration)
33
    {
34
        $this->configuration = $configuration;
35
36
        $this->processor = new TransactionProcessor($configuration);
37
        $this->hydrator = new TransactionHydrator($configuration);
38
    }
39
40
    public function getConfiguration(): Configuration
41
    {
42
        return $this->configuration;
43
    }
44
45
    public function populate(Transaction $transaction): void
46
    {
47
        $this->hydrator->hydrate($transaction);
48
    }
49
50
    public function process(Transaction $transaction): void
51
    {
52
        $this->processor->process($transaction);
53
    }
54
55
    /**
56
     * @param EntityManagerInterface $em
57
     *
58
     * @return EntityManagerInterface
59
     */
60
    public function selectStorageSpace(EntityManagerInterface $em): EntityManagerInterface
61
    {
62
        return $this->configuration->getEntityManager() ?? $em;
63
    }
64
}
65