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 | View Code Duplication | class SmartIdResult implements ResultInterface |
|
|
|||
10 | { |
||
11 | /** @var string response status */ |
||
12 | private $status; |
||
13 | |||
14 | /** @var string control code to display for user */ |
||
15 | private $controlCode; |
||
16 | |||
17 | /** @var string token for mobile status query */ |
||
18 | private $token; |
||
19 | |||
20 | /** |
||
21 | * Fields expected in response |
||
22 | * @return array |
||
23 | */ |
||
24 | 3 | public function getFields() |
|
32 | |||
33 | /** |
||
34 | * Set status |
||
35 | * @param string $status |
||
36 | * @return void |
||
37 | */ |
||
38 | 1 | public function setStatus($status) |
|
42 | |||
43 | /** |
||
44 | * Get status |
||
45 | * @return string |
||
46 | */ |
||
47 | 1 | public function getStatus() |
|
51 | |||
52 | /** |
||
53 | * Set control code |
||
54 | * @param string $controlCode |
||
55 | * @return void |
||
56 | */ |
||
57 | 1 | public function setControlCode($controlCode) |
|
61 | |||
62 | /** |
||
63 | * Get control code |
||
64 | * @return string |
||
65 | */ |
||
66 | 1 | public function getControlCode() |
|
70 | |||
71 | /** |
||
72 | * Set token |
||
73 | * @param string $token |
||
74 | * @return void |
||
75 | */ |
||
76 | 1 | public function setToken($token) |
|
80 | |||
81 | /** |
||
82 | * Get token |
||
83 | * @return string |
||
84 | */ |
||
85 | 1 | public function getToken() |
|
89 | } |
||
90 |
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.