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 ApiCoreTrait |
||
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 bgRewriteAoF() |
|
22 | { |
||
23 | 1 | $command = Enum::BGREWRITEAOF; |
|
24 | |||
25 | 1 | return $this->dispatch(Builder::build($command)); |
|
26 | } |
||
27 | |||
28 | /** |
||
29 | * @override |
||
30 | * @inheritDoc |
||
31 | */ |
||
32 | public function bgSave() |
||
38 | |||
39 | /** |
||
40 | * @override |
||
41 | * @inheritDoc |
||
42 | */ |
||
43 | public function sync() |
||
49 | |||
50 | /** |
||
51 | * @override |
||
52 | * @inheritDoc |
||
53 | */ |
||
54 | 1 | public function time() |
|
60 | |||
61 | /** |
||
62 | * @override |
||
63 | * @inheritDoc |
||
64 | */ |
||
65 | 1 | public function monitor() |
|
71 | |||
72 | /** |
||
73 | * @override |
||
74 | * @inheritDoc |
||
75 | */ |
||
76 | 1 | public function flushAll() |
|
82 | |||
83 | /** |
||
84 | * @override |
||
85 | * @inheritDoc |
||
86 | */ |
||
87 | 137 | public function flushDb() |
|
93 | |||
94 | /** |
||
95 | * @override |
||
96 | * @inheritDoc |
||
97 | */ |
||
98 | 137 | public function info($section = []) |
|
132 | |||
133 | /** |
||
134 | * @override |
||
135 | * @inheritDoc |
||
136 | */ |
||
137 | 1 | View Code Duplication | public function slaveOf($host, $port) |
144 | |||
145 | /** |
||
146 | * @override |
||
147 | * @inheritDoc |
||
148 | */ |
||
149 | public function slowLog($subCommand, array $args = []) |
||
156 | |||
157 | /** |
||
158 | * @override |
||
159 | * @inheritDoc |
||
160 | */ |
||
161 | 1 | public function save() |
|
167 | } |
||
168 |
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.