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 |
||
7 | abstract class SmsapiMessage |
||
8 | { |
||
9 | /** |
||
10 | * @internal |
||
11 | * @var array |
||
12 | */ |
||
13 | public $data = []; |
||
14 | |||
15 | /** |
||
16 | * @param string|string[] $to |
||
17 | * @return self |
||
18 | */ |
||
19 | 16 | public function to($to) |
|
26 | |||
27 | /** |
||
28 | * @param string $group |
||
29 | * @return self |
||
30 | */ |
||
31 | 15 | public function group($group) |
|
38 | |||
39 | /** |
||
40 | * @param int|string $date |
||
41 | * @return self |
||
42 | */ |
||
43 | 15 | public function date($date) |
|
50 | |||
51 | /** |
||
52 | * @param string $notifyUrl |
||
53 | * @return self |
||
54 | */ |
||
55 | 15 | public function notifyUrl($notifyUrl) |
|
62 | |||
63 | /** |
||
64 | * @param string $partner |
||
65 | * @return self |
||
66 | */ |
||
67 | 15 | public function partner($partner) |
|
74 | |||
75 | /** |
||
76 | * @param bool $test |
||
77 | * @return self |
||
78 | */ |
||
79 | 21 | View Code Duplication | public function test($test = true) |
86 | } |
||
87 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.