DoctrineDbalTransactionManager   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

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

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