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 ApiChannelTrait |
||
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 pSubscribe(...$patterns) |
||
29 | |||
30 | /** |
||
31 | * @override |
||
32 | * @inheritDoc |
||
33 | */ |
||
34 | public function pubSub($command, array $args = []) |
||
41 | |||
42 | /** |
||
43 | * @override |
||
44 | * @inheritDoc |
||
45 | */ |
||
46 | View Code Duplication | public function publish($channel, $message) |
|
54 | |||
55 | /** |
||
56 | * @override |
||
57 | * @inheritDoc |
||
58 | */ |
||
59 | public function pUnsubscribe(...$patterns) |
||
67 | |||
68 | /** |
||
69 | * @override |
||
70 | * @inheritDoc |
||
71 | */ |
||
72 | public function unSubscribe(...$channels) |
||
80 | |||
81 | /** |
||
82 | * @override |
||
83 | * @inheritDoc |
||
84 | */ |
||
85 | public function subscribe(...$channels) |
||
93 | } |
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.