Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
30 | class MysqliConnection implements Connection, PingableConnection, ServerInfoAwareConnection |
||
31 | { |
||
32 | /** |
||
33 | * Name of the option to set connection flags |
||
34 | */ |
||
35 | const OPTION_FLAGS = 'flags'; |
||
36 | |||
37 | /** |
||
38 | * @var \mysqli |
||
39 | */ |
||
40 | private $_conn; |
||
41 | |||
42 | /** |
||
43 | * @param array $params |
||
44 | * @param string $username |
||
45 | * @param string $password |
||
46 | * @param array $driverOptions |
||
47 | * |
||
48 | * @throws \Doctrine\DBAL\Driver\Mysqli\MysqliException |
||
49 | */ |
||
50 | 5 | public function __construct(array $params, $username, $password, array $driverOptions = []) |
|
84 | |||
85 | /** |
||
86 | * Retrieves mysqli native resource handle. |
||
87 | * |
||
88 | * Could be used if part of your application is not using DBAL. |
||
89 | * |
||
90 | * @return \mysqli |
||
91 | */ |
||
92 | public function getWrappedResourceHandle() |
||
96 | |||
97 | /** |
||
98 | * {@inheritdoc} |
||
99 | */ |
||
100 | public function getServerVersion() |
||
108 | |||
109 | /** |
||
110 | 1 | * {@inheritdoc} |
|
111 | */ |
||
112 | 1 | public function requiresQueryForServerVersion() |
|
116 | |||
117 | /** |
||
118 | * {@inheritdoc} |
||
119 | */ |
||
120 | public function prepare($prepareString) |
||
124 | |||
125 | /** |
||
126 | * {@inheritdoc} |
||
127 | */ |
||
128 | View Code Duplication | public function query() |
|
137 | |||
138 | /** |
||
139 | * {@inheritdoc} |
||
140 | */ |
||
141 | public function quote($input, $type = \PDO::PARAM_STR) |
||
145 | |||
146 | /** |
||
147 | * {@inheritdoc} |
||
148 | */ |
||
149 | public function exec($statement) |
||
157 | |||
158 | /** |
||
159 | * {@inheritdoc} |
||
160 | */ |
||
161 | public function lastInsertId($name = null) |
||
165 | |||
166 | /** |
||
167 | * {@inheritdoc} |
||
168 | */ |
||
169 | public function beginTransaction() |
||
175 | |||
176 | /** |
||
177 | * {@inheritdoc} |
||
178 | */ |
||
179 | public function commit() |
||
183 | |||
184 | /** |
||
185 | * {@inheritdoc}non-PHPdoc) |
||
186 | */ |
||
187 | public function rollBack() |
||
191 | |||
192 | /** |
||
193 | * {@inheritdoc} |
||
194 | */ |
||
195 | public function errorCode() |
||
199 | |||
200 | /** |
||
201 | * {@inheritdoc} |
||
202 | */ |
||
203 | public function errorInfo() |
||
207 | |||
208 | /** |
||
209 | * Apply the driver options to the connection. |
||
210 | * |
||
211 | * @param array $driverOptions |
||
212 | * |
||
213 | * @throws MysqliException When one of of the options is not supported. |
||
214 | 1 | * @throws MysqliException When applying doesn't work - e.g. due to incorrect value. |
|
215 | */ |
||
216 | private function setDriverOptions(array $driverOptions = []) |
||
257 | |||
258 | /** |
||
259 | * Pings the server and re-connects when `mysqli.reconnect = 1` |
||
260 | * |
||
261 | * @return bool |
||
262 | */ |
||
263 | public function ping() |
||
267 | |||
268 | /** |
||
269 | * Establish a secure connection |
||
270 | * |
||
271 | * @param array $params |
||
272 | * @throws MysqliException |
||
273 | 5 | */ |
|
274 | private function setSecureConnection(array $params) |
||
294 | } |
||
295 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..