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 | 1 | public function hDel($key, ...$fields) |
|
29 | |||
30 | /** |
||
31 | * @override |
||
32 | * @inheritDoc |
||
33 | */ |
||
34 | 1 | public function hGet($key, $field) |
|
41 | |||
42 | /** |
||
43 | * @override |
||
44 | * @inheritDoc |
||
45 | */ |
||
46 | 1 | public function hGetAll($key) |
|
66 | |||
67 | /** |
||
68 | * @override |
||
69 | * @inheritDoc |
||
70 | */ |
||
71 | 1 | public function hIncrBy($key, $field, $increment) |
|
78 | |||
79 | /** |
||
80 | * @override |
||
81 | * @inheritDoc |
||
82 | */ |
||
83 | 1 | public function hIncrByFloat($key, $field, $increment) |
|
90 | |||
91 | /** |
||
92 | * @override |
||
93 | * @inheritDoc |
||
94 | */ |
||
95 | 1 | View Code Duplication | public function hKeys($key) |
102 | |||
103 | /** |
||
104 | * @override |
||
105 | * @inheritDoc |
||
106 | */ |
||
107 | 1 | View Code Duplication | public function hLen($key) |
114 | |||
115 | /** |
||
116 | * @override |
||
117 | * @inheritDoc |
||
118 | */ |
||
119 | 1 | public function hMGet($key, ...$fields) |
|
127 | |||
128 | /** |
||
129 | * @override |
||
130 | * @inheritDoc |
||
131 | */ |
||
132 | 7 | public function hMSet($key, array $fvMap) |
|
148 | |||
149 | /** |
||
150 | * @override |
||
151 | * @inheritDoc |
||
152 | */ |
||
153 | 8 | public function hSet($key, $field, $value) |
|
160 | |||
161 | /** |
||
162 | * @override |
||
163 | * @inheritDoc |
||
164 | */ |
||
165 | 1 | public function hSetNx($key, $filed, $value) |
|
172 | |||
173 | /** |
||
174 | * @override |
||
175 | * @inheritDoc |
||
176 | */ |
||
177 | 1 | public function hStrLen($key, $field) |
|
184 | |||
185 | /** |
||
186 | * @override |
||
187 | * @inheritDoc |
||
188 | */ |
||
189 | 1 | View Code Duplication | public function hVals($key) |
196 | |||
197 | /** |
||
198 | * @override |
||
199 | * @inheritDoc |
||
200 | */ |
||
201 | 1 | public function hScan($key, $cursor, array $options = []) |
|
210 | |||
211 | /** |
||
212 | * @inheritDoc |
||
213 | */ |
||
214 | 1 | 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.