Completed
Push — yii2-stable ( 4ea3c0...01db8a )
by Edgard
12:40
created

Connection::close()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 7
ccs 6
cts 6
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
crap 2
1
<?php
2
/**
3
 * @link http://www.yiiframework.com/
4
 * @copyright Copyright (c) 2008 Yii Software LLC
5
 * @license http://www.yiiframework.com/license/
6
 */
7
8
namespace edgardmessias\db\firebird;
9
10
/**
11
 *
12
 * @author Edgard Lorraine Messias <[email protected]>
13
 * @since 2.0
14
 */
15
class Connection extends \yii\db\Connection
16
{
17
18
    /**
19
     * @inheritdoc
20
     */
21
    public $schemaMap = [
22
        'firebird' => 'edgardmessias\db\firebird\Schema', // Firebird
23
    ];
24
25
    /**
26
     * @inheritdoc
27
     */
28
    public $pdoClass = 'edgardmessias\db\firebird\PdoAdapter';
29
30
    /**
31
     * @inheritdoc
32
     */
33
    public $commandClass = 'edgardmessias\db\firebird\Command';
34
    /**
35
     * @var Transaction the currently active transaction
36
     */
37
    private $_transaction;
1 ignored issue
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
38
39
    /**
40
     * Returns the currently active transaction.
41
     * @return Transaction the currently active transaction. Null if no active transaction.
42
     */
43 124
    public function getTransaction()
44
    {
45 124
        return $this->_transaction && $this->_transaction->getIsActive() ? $this->_transaction : null;
46
    }
47
48
    /**
49
     * Starts a transaction.
50
     * @param string|null $isolationLevel The isolation level to use for this transaction.
51
     * See [[Transaction::begin()]] for details.
52
     * @return Transaction the transaction initiated
53
     */
54 6
    public function beginTransaction($isolationLevel = null)
55
    {
56 6
        $this->open();
57
58 6
        if (($transaction = $this->getTransaction()) === null) {
59 6
            $transaction = $this->_transaction = new Transaction(['db' => $this]);
60 6
        }
61 6
        $transaction->begin($isolationLevel);
62
63 6
        return $transaction;
64
    }
65
66 242
    public function close()
67
    {
68 242
        if ($this->pdo !== null) {
69 141
            $this->_transaction = null;
70 141
        }
71 242
        parent::close();
72 242
    }
73
}
74