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 = []) |
|
82 | |||
83 | /** |
||
84 | * Retrieves mysqli native resource handle. |
||
85 | * |
||
86 | * Could be used if part of your application is not using DBAL. |
||
87 | * |
||
88 | * @return \mysqli |
||
89 | */ |
||
90 | public function getWrappedResourceHandle() |
||
94 | |||
95 | /** |
||
96 | * {@inheritdoc} |
||
97 | * |
||
98 | * The server version detection includes a special case for MariaDB |
||
99 | * to support '5.5.5-' prefixed versions introduced in Maria 10+ |
||
100 | * @link https://jira.mariadb.org/browse/MDEV-4088 |
||
101 | */ |
||
102 | public function getServerVersion() |
||
103 | { |
||
104 | $serverInfos = $this->_conn->get_server_info(); |
||
105 | if (false !== stripos($serverInfos, 'mariadb')) { |
||
106 | return $serverInfos; |
||
107 | } |
||
108 | |||
109 | $majorVersion = floor($this->_conn->server_version / 10000); |
||
110 | $minorVersion = floor(($this->_conn->server_version - $majorVersion * 10000) / 100); |
||
111 | $patchVersion = floor($this->_conn->server_version - $majorVersion * 10000 - $minorVersion * 100); |
||
112 | |||
113 | return $majorVersion . '.' . $minorVersion . '.' . $patchVersion; |
||
114 | } |
||
115 | |||
116 | /** |
||
117 | * {@inheritdoc} |
||
118 | */ |
||
119 | 1 | public function requiresQueryForServerVersion() |
|
123 | |||
124 | /** |
||
125 | * {@inheritdoc} |
||
126 | */ |
||
127 | public function prepare($prepareString) |
||
131 | |||
132 | /** |
||
133 | * {@inheritdoc} |
||
134 | */ |
||
135 | View Code Duplication | public function query() |
|
144 | |||
145 | /** |
||
146 | * {@inheritdoc} |
||
147 | */ |
||
148 | public function quote($input, $type=\PDO::PARAM_STR) |
||
152 | |||
153 | /** |
||
154 | * {@inheritdoc} |
||
155 | */ |
||
156 | public function exec($statement) |
||
164 | |||
165 | /** |
||
166 | * {@inheritdoc} |
||
167 | */ |
||
168 | public function lastInsertId($name = null) |
||
172 | |||
173 | /** |
||
174 | * {@inheritdoc} |
||
175 | */ |
||
176 | public function beginTransaction() |
||
182 | |||
183 | /** |
||
184 | * {@inheritdoc} |
||
185 | */ |
||
186 | public function commit() |
||
190 | |||
191 | /** |
||
192 | * {@inheritdoc}non-PHPdoc) |
||
193 | */ |
||
194 | public function rollBack() |
||
198 | |||
199 | /** |
||
200 | * {@inheritdoc} |
||
201 | */ |
||
202 | public function errorCode() |
||
206 | |||
207 | /** |
||
208 | * {@inheritdoc} |
||
209 | */ |
||
210 | public function errorInfo() |
||
214 | |||
215 | /** |
||
216 | * Apply the driver options to the connection. |
||
217 | * |
||
218 | * @param array $driverOptions |
||
219 | * |
||
220 | * @throws MysqliException When one of of the options is not supported. |
||
221 | * @throws MysqliException When applying doesn't work - e.g. due to incorrect value. |
||
222 | */ |
||
223 | 1 | private function setDriverOptions(array $driverOptions = []) |
|
265 | |||
266 | /** |
||
267 | * Pings the server and re-connects when `mysqli.reconnect = 1` |
||
268 | * |
||
269 | * @return bool |
||
270 | */ |
||
271 | public function ping() |
||
275 | |||
276 | /** |
||
277 | * Establish a secure connection |
||
278 | * |
||
279 | * @param array $params |
||
280 | * @throws MysqliException |
||
281 | */ |
||
282 | 5 | private function setSecureConnection(array $params) |
|
306 | } |
||
307 |
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..