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 |
||
| 27 | class ClientLocal extends AbstractClient |
||
| 28 | { |
||
| 29 | /** |
||
| 30 | * @var BaseTableGateway[] |
||
| 31 | */ |
||
| 32 | protected $tableGateways = []; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var Connection |
||
| 36 | */ |
||
| 37 | protected $connection = null; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * ClientLocal constructor. |
||
| 41 | * |
||
| 42 | * @param $connection |
||
| 43 | */ |
||
| 44 | public function __construct($connection) |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @inheritDoc |
||
| 51 | */ |
||
| 52 | public function getTables(array $params = []) |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @inheritDoc |
||
| 59 | */ |
||
| 60 | public function getTable($tableName) |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @inheritDoc |
||
| 67 | */ |
||
| 68 | public function getColumns($tableName, array $params = []) |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @inheritDoc |
||
| 75 | */ |
||
| 76 | public function getColumn($tableName, $columnName) |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @inheritDoc |
||
| 83 | */ |
||
| 84 | public function getEntries($tableName, array $params = []) |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @inheritDoc |
||
| 93 | */ |
||
| 94 | public function getEntry($tableName, $id, array $params = []) |
||
| 101 | |||
| 102 | /** |
||
| 103 | * @inheritDoc |
||
| 104 | */ |
||
| 105 | public function getUsers(array $params = []) |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @inheritDoc |
||
| 113 | */ |
||
| 114 | public function getUser($id, array $params = []) |
||
| 118 | |||
| 119 | /** |
||
| 120 | * @inheritDoc |
||
| 121 | */ |
||
| 122 | public function getGroups(array $params = []) |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @inheritDoc |
||
| 129 | */ |
||
| 130 | public function getGroup($id, array $params = []) |
||
| 134 | |||
| 135 | /** |
||
| 136 | * @inheritDoc |
||
| 137 | */ |
||
| 138 | public function getGroupPrivileges($groupID) |
||
| 146 | |||
| 147 | /** |
||
| 148 | * @inheritDoc |
||
| 149 | */ |
||
| 150 | public function getFiles(array $params = []) |
||
| 154 | |||
| 155 | /** |
||
| 156 | * @inheritDoc |
||
| 157 | */ |
||
| 158 | public function getFile($id, array $params = []) |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @inheritDoc |
||
| 165 | */ |
||
| 166 | public function getSettings() |
||
| 170 | |||
| 171 | /** |
||
| 172 | * @inheritDoc |
||
| 173 | */ |
||
| 174 | public function getSettingsByCollection($collectionName) |
||
| 182 | |||
| 183 | /** |
||
| 184 | * @inheritDoc |
||
| 185 | */ |
||
| 186 | public function getMessages($userId) |
||
| 193 | |||
| 194 | /** |
||
| 195 | * @inheritDoc |
||
| 196 | */ |
||
| 197 | View Code Duplication | public function createEntry($tableName, array $data) |
|
| 212 | |||
| 213 | /** |
||
| 214 | * @inheritDoc |
||
| 215 | */ |
||
| 216 | View Code Duplication | public function updateEntry($tableName, $id, array $data) |
|
| 231 | |||
| 232 | /** |
||
| 233 | * @inheritDoc |
||
| 234 | */ |
||
| 235 | public function deleteEntry($tableName, $ids) |
||
| 248 | |||
| 249 | /** |
||
| 250 | * @inheritDoc |
||
| 251 | */ |
||
| 252 | public function createUser(array $data) |
||
| 256 | |||
| 257 | /** |
||
| 258 | * @inheritDoc |
||
| 259 | */ |
||
| 260 | public function updateUser($id, array $data) |
||
| 264 | |||
| 265 | /** |
||
| 266 | * @inheritDoc |
||
| 267 | */ |
||
| 268 | public function deleteUser($ids) |
||
| 272 | |||
| 273 | /** |
||
| 274 | * @inheritDoc |
||
| 275 | */ |
||
| 276 | public function createFile(File $file) |
||
| 282 | |||
| 283 | /** |
||
| 284 | * @inheritDoc |
||
| 285 | */ |
||
| 286 | public function updateFile($id, array $data) |
||
| 290 | |||
| 291 | /** |
||
| 292 | * @inheritDoc |
||
| 293 | */ |
||
| 294 | public function deleteFile($ids) |
||
| 298 | |||
| 299 | public function createPreferences($data) |
||
| 310 | |||
| 311 | /** |
||
| 312 | * @inheritdoc |
||
| 313 | */ |
||
| 314 | public function createBookmark($data) |
||
| 334 | |||
| 335 | /** |
||
| 336 | * @inheritdoc |
||
| 337 | */ |
||
| 338 | public function createColumn($data) |
||
| 358 | |||
| 359 | /** |
||
| 360 | * Get a table gateway for the given table name |
||
| 361 | * |
||
| 362 | * @param $tableName |
||
| 363 | * |
||
| 364 | * @return RelationalTableGateway |
||
| 365 | */ |
||
| 366 | protected function getTableGateway($tableName) |
||
| 375 | } |
||
| 376 |