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 ApiGeospatialTrait |
||
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 geoAdd($key, array $coordinates) |
||
30 | |||
31 | /** |
||
32 | * @override |
||
33 | * @inheritDoc |
||
34 | */ |
||
35 | public function geoHash($key, ...$members) |
||
40 | |||
41 | /** |
||
42 | * @override |
||
43 | * @inheritDoc |
||
44 | */ |
||
45 | public function geoPos($key, ...$members) |
||
54 | |||
55 | /** |
||
56 | * @override |
||
57 | * @inheritDoc |
||
58 | */ |
||
59 | public function geoDist($key, $memberA, $memberB, $unit) |
||
67 | |||
68 | /** |
||
69 | * @override |
||
70 | * @inheritDoc |
||
71 | */ |
||
72 | View Code Duplication | public function geoRadius($key, $longitude, $latitude, $unit, $command, $count, $sort) |
|
80 | |||
81 | /** |
||
82 | * @override |
||
83 | * @inheritDoc |
||
84 | */ |
||
85 | View Code Duplication | public function geoRadiusByMember($key, $member, $unit, $command, $count, $sort, $store, $storeDist) |
|
93 | } |
||
94 |
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.