Completed
Push — master ( 7f22a0...381ac2 )
by Rémi
04:04
created

DoctrineEntityManager::rollback()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 5
nc 2
nop 0
crap 2
1
<?php
2
3
namespace RemiSan\TransactionManager\Doctrine;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use RemiSan\TransactionManager\Exception\BeginException;
7
use RemiSan\TransactionManager\Exception\CommitException;
8
use RemiSan\TransactionManager\Exception\RollbackException;
9
use RemiSan\TransactionManager\Transactional;
10
11
class DoctrineEntityManager implements Transactional
12
{
13
    /**
14
     * @var EntityManagerInterface
15
     */
16
    private $entityManager;
17
18
    /**
19
     * Constructor.
20
     *
21
     * @param EntityManagerInterface $entityManager
22
     */
23 21
    public function __construct(EntityManagerInterface $entityManager)
24
    {
25 21
        $this->entityManager = $entityManager;
26 21
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 6
    public function beginTransaction()
32
    {
33
        try {
34 6
            $this->entityManager->beginTransaction();
35 5
        } catch (\Exception $e) {
36 3
            throw new BeginException('Cannot begin Doctrine ORM transaction', $e->getCode(), $e);
37
        }
38 3
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 6
    public function commit()
44
    {
45
        try {
46 6
            $this->entityManager->commit();
47 5
        } catch (\Exception $e) {
48 3
            throw new CommitException('Cannot commit Doctrine ORM transaction', $e->getCode(), $e);
49
        }
50 3
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55 6
    public function rollback()
56
    {
57
        try {
58 6
            $this->entityManager->rollback();
59 5
        } catch (\Exception $e) {
60 3
            throw new RollbackException('Cannot rollback Doctrine ORM transaction', $e->getCode(), $e);
61
        }
62 3
    }
63
}
64