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

DoctrineDbalTransactionManager::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
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