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 |
||
| 32 | class MysqliConnection implements Connection, PingableConnection, ServerInfoAwareConnection |
||
| 33 | { |
||
| 34 | /** |
||
| 35 | * Name of the option to set connection flags |
||
| 36 | */ |
||
| 37 | const OPTION_FLAGS = 'flags'; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var \mysqli |
||
| 41 | */ |
||
| 42 | private $_conn; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var LastInsertId |
||
| 46 | */ |
||
| 47 | private $lastInsertId; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @param array $params |
||
| 51 | * @param string $username |
||
| 52 | * @param string $password |
||
| 53 | * @param array $driverOptions |
||
| 54 | * |
||
| 55 | * @throws \Doctrine\DBAL\Driver\Mysqli\MysqliException |
||
| 56 | */ |
||
| 57 | 5 | public function __construct(array $params, $username, $password, array $driverOptions = []) |
|
| 91 | |||
| 92 | /** |
||
| 93 | * Retrieves mysqli native resource handle. |
||
| 94 | * |
||
| 95 | * Could be used if part of your application is not using DBAL. |
||
| 96 | * |
||
| 97 | * @return \mysqli |
||
| 98 | */ |
||
| 99 | public function getWrappedResourceHandle() |
||
| 103 | |||
| 104 | /** |
||
| 105 | * {@inheritdoc} |
||
| 106 | */ |
||
| 107 | public function getServerVersion() |
||
| 115 | |||
| 116 | /** |
||
| 117 | * {@inheritdoc} |
||
| 118 | */ |
||
| 119 | 1 | public function requiresQueryForServerVersion() |
|
| 123 | |||
| 124 | /** |
||
| 125 | * {@inheritdoc} |
||
| 126 | * |
||
| 127 | * @throws \Doctrine\DBAL\Driver\Mysqli\MysqliException |
||
| 128 | */ |
||
| 129 | public function prepare($prepareString) : Statement |
||
| 133 | |||
| 134 | /** |
||
| 135 | * {@inheritdoc} |
||
| 136 | */ |
||
| 137 | View Code Duplication | public function query() |
|
| 146 | |||
| 147 | /** |
||
| 148 | * {@inheritdoc} |
||
| 149 | */ |
||
| 150 | public function quote($input, $type=\PDO::PARAM_STR) |
||
| 154 | |||
| 155 | /** |
||
| 156 | * {@inheritdoc} |
||
| 157 | * |
||
| 158 | * @throws \Doctrine\DBAL\Driver\Mysqli\MysqliException |
||
| 159 | */ |
||
| 160 | public function exec($statement) |
||
| 170 | |||
| 171 | /** |
||
| 172 | * {@inheritdoc} |
||
| 173 | */ |
||
| 174 | public function lastInsertId($name = null) : string |
||
| 178 | |||
| 179 | /** |
||
| 180 | * {@inheritdoc} |
||
| 181 | */ |
||
| 182 | public function beginTransaction() |
||
| 188 | |||
| 189 | /** |
||
| 190 | * {@inheritdoc} |
||
| 191 | */ |
||
| 192 | public function commit() |
||
| 196 | |||
| 197 | /** |
||
| 198 | * {@inheritdoc}non-PHPdoc) |
||
| 199 | */ |
||
| 200 | public function rollBack() |
||
| 204 | |||
| 205 | /** |
||
| 206 | * {@inheritdoc} |
||
| 207 | */ |
||
| 208 | public function errorCode() |
||
| 212 | |||
| 213 | /** |
||
| 214 | * {@inheritdoc} |
||
| 215 | */ |
||
| 216 | public function errorInfo() |
||
| 220 | |||
| 221 | /** |
||
| 222 | * Apply the driver options to the connection. |
||
| 223 | * |
||
| 224 | * @param array $driverOptions |
||
| 225 | * |
||
| 226 | * @throws MysqliException When one of of the options is not supported. |
||
| 227 | * @throws MysqliException When applying doesn't work - e.g. due to incorrect value. |
||
| 228 | */ |
||
| 229 | 1 | private function setDriverOptions(array $driverOptions = []) |
|
| 271 | |||
| 272 | /** |
||
| 273 | * Pings the server and re-connects when `mysqli.reconnect = 1` |
||
| 274 | * |
||
| 275 | * @return bool |
||
| 276 | */ |
||
| 277 | public function ping() |
||
| 281 | |||
| 282 | /** |
||
| 283 | * Establish a secure connection |
||
| 284 | * |
||
| 285 | * @param array $params |
||
| 286 | * @throws MysqliException |
||
| 287 | */ |
||
| 288 | 5 | private function setSecureConnection(array $params) |
|
| 312 | } |
||
| 313 |
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..