Passed
Pull Request — master (#188)
by Damien
03:02
created

TransactionManager::populate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

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