Completed
Push — develop ( 4ea5a3...a8c617 )
by Bartko
05:56
created

rollbackTransaction()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 9.4285
cc 2
eloc 3
nc 2
nop 0
crap 6
1
<?php
2
namespace StefanoTree\NestedSet\Adapter;
3
4
abstract class NestedTransactionDbAdapterAbstract
5
    implements AdapterInterface
0 ignored issues
show
Coding Style introduced by
The implements keyword must be on the same line as the class name
Loading history...
6
{
7
    private $outerTransactionWasStarted = false;
8
9
    /**
10
     * Start DB transaction
11
     */
12
    abstract protected function _beginTransaction();
13
14
    /**
15
     * Commit DB transaction
16
     */
17
    abstract protected function _commitTransaction();
18
19
    /**
20
     * Rollback DB transaction
21
     */
22
    abstract protected function _rollbackTransaction();
23
24
    /**
25
     * Check if DB transaction has been started
26
     * @return boolean
27
     */
28
    abstract protected function _isInTransaction();
29
30 12
    public function beginTransaction()
31
    {
32 12
        $this->outerTransactionWasStarted = $this->_isInTransaction();
33
34 12
        if (!$this->outerTransactionWasStarted) {
35 12
            $this->_beginTransaction();
36 12
        }
37 12
    }
38
39 12
    public function commitTransaction()
40
    {
41 12
        if (!$this->outerTransactionWasStarted) {
42 12
            $this->_commitTransaction();
43 12
        }
44 12
    }
45
46
    public function rollbackTransaction()
47
    {
48
        if (!$this->outerTransactionWasStarted) {
49
            $this->_rollbackTransaction();
50
        }
51
    }
52
}
53