Completed
Push — master ( 3633f5...fa8aa1 )
by Rémi
03:57
created

DoctrineDbalTransactionManager   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
c 1
b 0
f 1
lcom 1
cbo 4
dl 0
loc 47
rs 10

4 Methods

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