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 | public function getServerVersion() |
||
| 112 | |||
| 113 | /** |
||
| 114 | * {@inheritdoc} |
||
| 115 | */ |
||
| 116 | 1 | public function requiresQueryForServerVersion() |
|
| 120 | |||
| 121 | /** |
||
| 122 | * {@inheritdoc} |
||
| 123 | */ |
||
| 124 | public function prepare($prepareString) |
||
| 128 | |||
| 129 | /** |
||
| 130 | * {@inheritdoc} |
||
| 131 | */ |
||
| 132 | View Code Duplication | public function query() |
|
| 141 | |||
| 142 | /** |
||
| 143 | * {@inheritdoc} |
||
| 144 | */ |
||
| 145 | public function quote($input, $type=\PDO::PARAM_STR) |
||
| 149 | |||
| 150 | /** |
||
| 151 | * {@inheritdoc} |
||
| 152 | */ |
||
| 153 | public function exec($statement) |
||
| 161 | |||
| 162 | /** |
||
| 163 | * {@inheritdoc} |
||
| 164 | */ |
||
| 165 | public function lastInsertId($name = null) |
||
| 169 | |||
| 170 | /** |
||
| 171 | * {@inheritdoc} |
||
| 172 | */ |
||
| 173 | public function beginTransaction() |
||
| 179 | |||
| 180 | /** |
||
| 181 | * {@inheritdoc} |
||
| 182 | */ |
||
| 183 | public function commit() |
||
| 187 | |||
| 188 | /** |
||
| 189 | * {@inheritdoc}non-PHPdoc) |
||
| 190 | */ |
||
| 191 | public function rollBack() |
||
| 195 | |||
| 196 | /** |
||
| 197 | * {@inheritdoc} |
||
| 198 | */ |
||
| 199 | public function errorCode() |
||
| 203 | |||
| 204 | /** |
||
| 205 | * {@inheritdoc} |
||
| 206 | */ |
||
| 207 | public function errorInfo() |
||
| 211 | |||
| 212 | /** |
||
| 213 | * Apply the driver options to the connection. |
||
| 214 | * |
||
| 215 | * @param array $driverOptions |
||
| 216 | * |
||
| 217 | * @throws MysqliException When one of of the options is not supported. |
||
| 218 | * @throws MysqliException When applying doesn't work - e.g. due to incorrect value. |
||
| 219 | */ |
||
| 220 | 1 | private function setDriverOptions(array $driverOptions = []) |
|
| 262 | |||
| 263 | /** |
||
| 264 | * Pings the server and re-connects when `mysqli.reconnect = 1` |
||
| 265 | * |
||
| 266 | * @return bool |
||
| 267 | */ |
||
| 268 | public function ping() |
||
| 272 | |||
| 273 | /** |
||
| 274 | * Establish a secure connection |
||
| 275 | * |
||
| 276 | * @param array $params |
||
| 277 | * @throws MysqliException |
||
| 278 | */ |
||
| 279 | 5 | private function setSecureConnection(array $params) |
|
| 303 | } |
||
| 304 |
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..