Passed
Push — master ( 76b08e...5cd6b2 )
by Ryuichi
58:40 queued 56:20
created

DatabaseDriver::setTransactionIsolation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace WebStream\Database\Driver;
4
5
use WebStream\DI\Injector;
0 ignored issues
show
Bug introduced by
The type WebStream\DI\Injector was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use WebStream\Container\Container;
0 ignored issues
show
Bug introduced by
The type WebStream\Container\Container was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
8
/**
9
 * DatabaseDriver
10
 * @author Ryuichi TANAKA.
11
 * @since 2013/12/07
12
 * @version 0.4
13
 */
14
abstract class DatabaseDriver
15
{
16
    use Injector;
17
18
    /**
19
     * @var \Doctrine\DBAL\Connection DBオブジェクト
20
     */
21
    protected $connection;
22
23
    /**
24
     * @var Container DB接続設定
25
     */
26
    protected $config;
27
28
    /**
29
     * constructor
30
     */
31 52
    public function __construct(Container $config)
32
    {
33 52
        $this->config = $config;
34 52
    }
35
36
    /**
37
     * destructor
38
     */
39
    public function __destruct()
40
    {
41
        // $this->logger->debug("Release driver: " . get_class($this));
42
    }
43
44
    /**
45
     * 接続する
46
     */
47
    abstract public function connect();
48
49
    /**
50
     * 切断する
51
     */
52 52
    public function disconnect()
53
    {
54 52
        if ($this->connection !== null) {
55 52
            $this->logger->debug("Database disconnect.");
56 52
            $this->connection->close();
57 52
            $this->connection = null;
58
        }
59 52
    }
60
61
    /**
62
     * トランザクションを開始する
63
     * @return boolean トランザクション開始結果
64
     */
65 16
    public function beginTransaction()
66
    {
67 16
        $inTransaction = false;
68 16
        if ($this->connection !== null) {
69 16
            $this->connection->beginTransaction();
70 16
            $inTransaction = $this->inTransaction();
71
        }
72
73 16
        return $inTransaction;
74
    }
75
76
    /**
77
     * コミットする
78
     */
79 8
    public function commit()
80
    {
81 8
        if ($this->connection !== null) {
82 8
            $this->connection->commit();
83
        }
84 8
    }
85
86
    /**
87
     * ロールバックする
88
     */
89 16
    public function rollback()
90
    {
91 16
        if ($this->inTransaction()) {
92 16
            $this->connection->rollBack();
93
        }
94 16
    }
95
96
    /**
97
     * 自動コミットフラグを設定する
98
     * @param bool $isAutoCommit 自動コミットフラグ
99
     */
100 16
    public function setAutoCommit(bool $isAutoCommit)
101
    {
102 16
        $this->connection->setAutoCommit($isAutoCommit);
103 16
    }
104
105
    /**
106
     * DB接続されているか
107
     * @return bool 接続有無
108
     */
109
    public function isConnected()
110
    {
111
        return $this->connection !== null;
112
    }
113
114
    /**
115
     * トランザクション内かどうか
116
     * @return bool トランザクション内かどうか
117
     */
118 52
    public function inTransaction()
119
    {
120 52
        return $this->connection !== null ? $this->connection->isTransactionActive() : false;
121
    }
122
123
    /**
124
     * SQLをセットしてステートメントを返却する
125
     * @param string SQL
126
     * @return \Doctrine\DBAL\Driver\DriverStatement ステートメント
0 ignored issues
show
Bug introduced by
The type Doctrine\DBAL\Driver\DriverStatement was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
127
     */
128 52
    public function getStatement(string $sql)
129
    {
130 52
        return $this->connection !== null ? $this->connection->prepare($sql) : null;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->connection...n->prepare($sql) : null also could return the type Doctrine\DBAL\Statement which is incompatible with the documented return type Doctrine\DBAL\Driver\DriverStatement.
Loading history...
131
    }
132
133
    /**
134
     * トランザクション分離レベルを返却する
135
     * @return int トランザクション分離レベル
136
     */
137
    public function getTransactionIsolation()
138
    {
139
        return $this->connection->getTransactionIsolation();
140
    }
141
142
    /**
143
     * トランザクション分離レベルを設定する
144
     * @param int $isolationLevel トランザクション分離レベル
145
     */
146 16
    public function setTransactionIsolation(int $isolationLevel)
147
    {
148 16
        $this->connection->setTransactionIsolation($isolationLevel);
149 16
    }
150
}
151