Completed
Push — master ( ebead9...8550db )
by Rémi
05:01 queued 03:23
created

DoctrineDbalConnectionTransactionManager   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 4
dl 0
loc 53
ccs 0
cts 28
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A beginTransaction() 0 8 2
A commit() 0 8 2
A rollback() 0 8 2
1
<?php
2
3
namespace RemiSan\TransactionManager\Doctrine;
4
5
use Doctrine\DBAL\Connection;
6
use Doctrine\DBAL\ConnectionException;
7
use RemiSan\TransactionManager\Exception\BeginException;
8
use RemiSan\TransactionManager\Exception\CommitException;
9
use RemiSan\TransactionManager\Exception\RollbackException;
10
use RemiSan\TransactionManager\Transactional;
11
12
final class DoctrineDbalConnectionTransactionManager implements Transactional
13
{
14
    /**
15
     * @var Connection
16
     */
17
    private $dbalConnection;
18
19
    /**
20
     * Constructor.
21
     *
22
     * @param Connection $dbalConnection
23
     */
24
    public function __construct(Connection $dbalConnection)
25
    {
26
        $this->dbalConnection = $dbalConnection;
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function beginTransaction()
33
    {
34
        try {
35
            $this->dbalConnection->beginTransaction();
36
        } catch (\Exception $e) {
37
            throw new BeginException('Cannot begin Doctrine DBAL transaction');
38
        }
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function commit()
45
    {
46
        try {
47
            $this->dbalConnection->commit();
48
        } catch (ConnectionException $e) {
49
            throw new CommitException('Cannot commit Doctrine DBAL transaction');
50
        }
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function rollback()
57
    {
58
        try {
59
            $this->dbalConnection->commit();
60
        } catch (ConnectionException $e) {
61
            throw new RollbackException('Cannot rollback Doctrine DBAL transaction');
62
        }
63
    }
64
}
65