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 |
||
| 9 | trait ApiSetHashTrait |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @param Request $request |
||
| 13 | * @return mixed |
||
| 14 | */ |
||
| 15 | abstract function dispatch(Request $request); |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @override |
||
| 19 | * @inheritDoc |
||
| 20 | */ |
||
| 21 | public function hDel($key, ...$fields) |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @override |
||
| 32 | * @inheritDoc |
||
| 33 | */ |
||
| 34 | public function hGet($key, $field) |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @override |
||
| 44 | * @inheritDoc |
||
| 45 | */ |
||
| 46 | public function hGetAll($key) |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @override |
||
| 69 | * @inheritDoc |
||
| 70 | */ |
||
| 71 | public function hIncrBy($key, $field, $increment) |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @override |
||
| 81 | * @inheritDoc |
||
| 82 | */ |
||
| 83 | public function hIncrByFloat($key, $field, $increment) |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @override |
||
| 93 | * @inheritDoc |
||
| 94 | */ |
||
| 95 | View Code Duplication | public function hKeys($key) |
|
| 102 | |||
| 103 | /** |
||
| 104 | * @override |
||
| 105 | * @inheritDoc |
||
| 106 | */ |
||
| 107 | View Code Duplication | public function hLen($key) |
|
| 114 | |||
| 115 | /** |
||
| 116 | * @override |
||
| 117 | * @inheritDoc |
||
| 118 | */ |
||
| 119 | public function hMGet($key, ...$fields) |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @override |
||
| 130 | * @inheritDoc |
||
| 131 | */ |
||
| 132 | public function hMSet($key, array $fvMap) |
||
| 147 | |||
| 148 | /** |
||
| 149 | * @override |
||
| 150 | * @inheritDoc |
||
| 151 | */ |
||
| 152 | public function hSet($key, $field, $value) |
||
| 159 | |||
| 160 | /** |
||
| 161 | * @override |
||
| 162 | * @inheritDoc |
||
| 163 | */ |
||
| 164 | public function hSetNx($key, $filed, $value) |
||
| 171 | |||
| 172 | /** |
||
| 173 | * @override |
||
| 174 | * @inheritDoc |
||
| 175 | */ |
||
| 176 | public function hStrLen($key, $field) |
||
| 183 | |||
| 184 | /** |
||
| 185 | * @override |
||
| 186 | * @inheritDoc |
||
| 187 | */ |
||
| 188 | View Code Duplication | public function hVals($key) |
|
| 195 | |||
| 196 | /** |
||
| 197 | * @override |
||
| 198 | * @inheritDoc |
||
| 199 | */ |
||
| 200 | public function hScan($key, $cursor, array $options = []) |
||
| 209 | |||
| 210 | /** |
||
| 211 | * @inheritDoc |
||
| 212 | */ |
||
| 213 | public function hExists($key, $field) |
||
| 221 | } |
||
| 222 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.