DatabaseDriver::setTransactionIsolation()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
namespace WebStream\Database\Driver;
3
4
use WebStream\DI\Injector;
5
use WebStream\Container\Container;
6
use Doctrine\DBAL\Connection;
0 ignored issues
show
Bug introduced by
The type Doctrine\DBAL\Connection 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 object DBオブジェクト
20
     */
21
    protected $connection;
22
23
    /**
24
     * @var Container DB接続設定
25
     */
26
    protected $config;
27
28
    /**
29
     * constructor
30
     */
31
    public function __construct(Container $config)
32
    {
33
        $this->config = $config;
34
    }
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
    public function disconnect()
53
    {
54
        if ($this->connection !== null) {
55
            $this->logger->debug("Database disconnect.");
0 ignored issues
show
Bug Best Practice introduced by
The property logger does not exist on WebStream\Database\Driver\DatabaseDriver. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug introduced by
The method debug() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

55
            $this->logger->/** @scrutinizer ignore-call */ 
56
                           debug("Database disconnect.");

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
56
            $this->connection->close();
57
            $this->connection = null;
58
        }
59
    }
60
61
    /**
62
     * トランザクションを開始する
63
     * @return boolean トランザクション開始結果
64
     */
65
    public function beginTransaction()
66
    {
67
        $inTransaction = false;
68
        if ($this->connection !== null) {
69
            $this->connection->beginTransaction();
70
            $inTransaction = $this->inTransaction();
71
        }
72
73
        return $inTransaction;
74
    }
75
76
    /**
77
     * コミットする
78
     */
79
    public function commit()
80
    {
81
        if ($this->connection !== null) {
82
            $this->connection->commit();
83
        }
84
    }
85
86
    /**
87
     * ロールバックする
88
     */
89
    public function rollback()
90
    {
91
        if ($this->inTransaction()) {
92
            $this->connection->rollBack();
93
        }
94
    }
95
96
    /**
97
     * 自動コミットフラグを設定する
98
     * @param bool $isAutoCommit 自動コミットフラグ
99
     */
100
    public function setAutoCommit(bool $isAutoCommit)
101
    {
102
        $this->connection->setAutoCommit($isAutoCommit);
103
    }
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
    public function inTransaction()
119
    {
120
        return $this->connection !== null ? $this->connection->isTransactionActive() : false;
121
    }
122
123
    /**
124
     * SQLをセットしてステートメントを返却する
125
     * @param string SQL
126
     * @return object ステートメント
127
     */
128
    public function getStatement(string $sql)
129
    {
130
        return $this->connection !== null ? $this->connection->prepare($sql) : null;
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
    public function setTransactionIsolation(int $isolationLevel)
147
    {
148
        $this->connection->setTransactionIsolation($isolationLevel);
149
    }
150
}
151