1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\EntityManager\RetryConnection; |
6
|
|
|
|
7
|
|
|
use Doctrine\DBAL\Driver\Statement as DriverStatement; |
8
|
|
|
use Doctrine\DBAL\ParameterType; |
9
|
|
|
use IteratorAggregate; |
10
|
|
|
use PDO; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @SuppressWarnings(PHPMD.TooManyPublicMethods) |
14
|
|
|
*/ |
15
|
|
|
class Statement implements IteratorAggregate, DriverStatement |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var PingingAndReconnectingConnection |
19
|
|
|
*/ |
20
|
|
|
private $connection; |
21
|
|
|
/** |
22
|
|
|
* @var array |
23
|
|
|
*/ |
24
|
|
|
private $params = []; |
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
private $sql; |
29
|
|
|
/**y |
30
|
|
|
* |
31
|
|
|
* @var array |
32
|
|
|
*/ |
33
|
|
|
private $values = []; |
34
|
|
|
/** |
35
|
|
|
* @TODO Required setting as mixed due to stan reasons, pending a better solution |
36
|
|
|
* @var mixed |
37
|
|
|
*/ |
38
|
|
|
private $wrappedStatement; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param string $sql |
42
|
|
|
* @param PingingAndReconnectingConnection $conn |
43
|
|
|
*/ |
44
|
|
|
public function __construct( |
45
|
|
|
string $sql, |
46
|
|
|
PingingAndReconnectingConnection $conn |
47
|
|
|
) { |
48
|
|
|
$this->sql = $sql; |
49
|
|
|
$this->connection = $conn; |
50
|
|
|
$this->createStatement(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Create Statement. |
55
|
|
|
*/ |
56
|
|
|
private function createStatement() |
57
|
|
|
{ |
58
|
|
|
$this->wrappedStatement = $this->connection->prepareUnwrapped($this->sql); |
59
|
|
|
foreach ($this->params as $params) { |
60
|
|
|
$this->bindParam(...$params); |
|
|
|
|
61
|
|
|
} |
62
|
|
|
$this->params = []; |
63
|
|
|
foreach ($this->values as $values) { |
64
|
|
|
$this->bindValue(...$values); |
|
|
|
|
65
|
|
|
} |
66
|
|
|
$this->values = []; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @inheritdoc |
71
|
|
|
*/ |
72
|
|
|
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null) |
73
|
|
|
{ |
74
|
|
|
$this->params[] = [$column, $variable, $type, $length]; |
75
|
|
|
|
76
|
|
|
return $this->wrappedStatement->bindParam($column, $variable, $type, $length); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @inheritdoc |
81
|
|
|
*/ |
82
|
|
|
public function bindValue($param, $value, $type = ParameterType::STRING) |
83
|
|
|
{ |
84
|
|
|
$this->values[] = [$param, $value, $type]; |
85
|
|
|
|
86
|
|
|
return $this->wrappedStatement->bindValue($param, $value, $type); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @inheritdoc |
91
|
|
|
*/ |
92
|
|
|
public function closeCursor() |
93
|
|
|
{ |
94
|
|
|
return $this->wrappedStatement->closeCursor(); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @inheritdoc |
99
|
|
|
*/ |
100
|
|
|
public function columnCount() |
101
|
|
|
{ |
102
|
|
|
return $this->wrappedStatement->columnCount(); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @inheritdoc |
107
|
|
|
*/ |
108
|
|
|
public function errorCode() |
109
|
|
|
{ |
110
|
|
|
return $this->wrappedStatement->errorCode(); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @inheritdoc |
115
|
|
|
*/ |
116
|
|
|
public function errorInfo() |
117
|
|
|
{ |
118
|
|
|
return $this->wrappedStatement->errorInfo(); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @inheritdoc |
123
|
|
|
*/ |
124
|
|
|
public function execute($params = null) |
125
|
|
|
{ |
126
|
|
|
return $this->wrappedStatement->execute($params); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @inheritdoc |
131
|
|
|
*/ |
132
|
|
|
public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0) |
133
|
|
|
{ |
134
|
|
|
return $this->wrappedStatement->fetch($fetchMode, $cursorOrientation, $cursorOffset); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @inheritdoc |
139
|
|
|
*/ |
140
|
|
|
public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null) |
141
|
|
|
{ |
142
|
|
|
return $this->wrappedStatement->fetchAll($fetchMode, $fetchArgument, $ctorArgs); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @inheritdoc |
147
|
|
|
*/ |
148
|
|
|
public function fetchColumn($columnIndex = 0) |
149
|
|
|
{ |
150
|
|
|
return $this->wrappedStatement->fetchColumn($columnIndex); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @inheritdoc |
155
|
|
|
*/ |
156
|
|
|
public function getIterator() |
157
|
|
|
{ |
158
|
|
|
return $this->wrappedStatement->getIterator(); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @inheritdoc |
163
|
|
|
*/ |
164
|
|
|
public function rowCount() |
165
|
|
|
{ |
166
|
|
|
return $this->wrappedStatement->rowCount(); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @inheritdoc |
171
|
|
|
*/ |
172
|
|
|
public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null) |
173
|
|
|
{ |
174
|
|
|
return $this->wrappedStatement->setFetchMode($fetchMode, $arg2, $arg3); |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.