DoctrineDbalTransactionManager::beginTransaction()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 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