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 ApiClusterTrait |
||
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 clusterAddSlots(...$slots) |
||
29 | |||
30 | /** |
||
31 | * @override |
||
32 | * @inheritDoc |
||
33 | */ |
||
34 | public function clusterCountFailureReports($nodeId) |
||
42 | |||
43 | /** |
||
44 | * @override |
||
45 | * @inheritDoc |
||
46 | */ |
||
47 | public function clusterCountKeysInSlot($slot) |
||
55 | |||
56 | /** |
||
57 | * @override |
||
58 | * @inheritDoc |
||
59 | */ |
||
60 | public function clusterDelSlots(...$slots) |
||
68 | |||
69 | /** |
||
70 | * @override |
||
71 | * @inheritDoc |
||
72 | */ |
||
73 | public function clusterFailOver($operation) |
||
77 | |||
78 | /** |
||
79 | * @override |
||
80 | * @inheritDoc |
||
81 | */ |
||
82 | public function clusterForget($nodeId) |
||
86 | |||
87 | /** |
||
88 | * @override |
||
89 | * @inheritDoc |
||
90 | */ |
||
91 | public function clusterGetKeyInSlot($slot, $count) |
||
95 | |||
96 | /** |
||
97 | * @override |
||
98 | * @inheritDoc |
||
99 | */ |
||
100 | public function clusterInfo() |
||
107 | |||
108 | /** |
||
109 | * @override |
||
110 | * @inheritDoc |
||
111 | */ |
||
112 | View Code Duplication | public function clusterKeySlot($key) |
|
120 | |||
121 | /** |
||
122 | * @override |
||
123 | * @inheritDoc |
||
124 | */ |
||
125 | public function clusterMeet($ip, $port) |
||
133 | |||
134 | /** |
||
135 | * @override |
||
136 | * @inheritDoc |
||
137 | */ |
||
138 | public function clusterNodes() |
||
142 | |||
143 | /** |
||
144 | * @override |
||
145 | * @inheritDoc |
||
146 | */ |
||
147 | public function clusterReplicate($nodeId) |
||
151 | |||
152 | /** |
||
153 | * @override |
||
154 | * @inheritDoc |
||
155 | */ |
||
156 | public function clusterReset($mode) |
||
160 | |||
161 | /** |
||
162 | * @override |
||
163 | * @inheritDoc |
||
164 | */ |
||
165 | public function clusterSaveConfig() |
||
169 | |||
170 | /** |
||
171 | * @override |
||
172 | * @inheritDoc |
||
173 | */ |
||
174 | public function clusterSetConfigEpoch($configEpoch) |
||
178 | |||
179 | /** |
||
180 | * @inheritDoc |
||
181 | */ |
||
182 | public function clusterSetSlot($command, $nodeId) |
||
190 | |||
191 | /** |
||
192 | * @override |
||
193 | * @inheritDoc |
||
194 | */ |
||
195 | public function clusterSlaves($nodeId) |
||
203 | |||
204 | /** |
||
205 | * @override |
||
206 | * @inheritDoc |
||
207 | */ |
||
208 | public function clusterSlots() |
||
215 | |||
216 | /** |
||
217 | * @override |
||
218 | * @inheritDoc |
||
219 | */ |
||
220 | public function readOnly() |
||
227 | |||
228 | /** |
||
229 | * @override |
||
230 | * @inheritDoc |
||
231 | */ |
||
232 | 1 | public function readWrite() |
|
239 | } |
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.