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 SmartIdStatusResult extends AbstractStatusResult |
|
|
|||
10 | { |
||
11 | /** @var string user's login certificate */ |
||
12 | private $certificate; |
||
13 | |||
14 | /** @var string personal code */ |
||
15 | private $code; |
||
16 | |||
17 | /** @var string Country code */ |
||
18 | private $country; |
||
19 | |||
20 | /** @var string name */ |
||
21 | private $name; |
||
22 | |||
23 | /** @var string surname */ |
||
24 | private $surname; |
||
25 | |||
26 | /** |
||
27 | * Fields expected in response |
||
28 | * @return array |
||
29 | */ |
||
30 | 12 | public function getFields() |
|
41 | |||
42 | /** |
||
43 | * @return string |
||
44 | */ |
||
45 | 2 | public function getStatus() |
|
49 | |||
50 | /** |
||
51 | * @return string |
||
52 | */ |
||
53 | 2 | public function getCode() |
|
57 | |||
58 | /** |
||
59 | * @return string |
||
60 | */ |
||
61 | 2 | public function getCountry() |
|
65 | |||
66 | /** |
||
67 | * @return string |
||
68 | */ |
||
69 | 2 | public function getName() |
|
73 | |||
74 | /** |
||
75 | * @return string |
||
76 | */ |
||
77 | 2 | public function getSurname() |
|
81 | |||
82 | /** |
||
83 | * Set status |
||
84 | * @param string $status |
||
85 | * @return void |
||
86 | */ |
||
87 | 2 | public function setStatus($status) |
|
91 | |||
92 | /** |
||
93 | * Set code |
||
94 | * @param string $code |
||
95 | * @return void |
||
96 | */ |
||
97 | 2 | public function setCode($code) |
|
101 | |||
102 | /** |
||
103 | * Set country |
||
104 | * @param string $country |
||
105 | * @return void |
||
106 | */ |
||
107 | 2 | public function setCountry($country) |
|
111 | |||
112 | /** |
||
113 | * Set name |
||
114 | * @param string $name |
||
115 | * @return void |
||
116 | */ |
||
117 | 2 | public function setName($name) |
|
121 | |||
122 | /** |
||
123 | * Set surname |
||
124 | * @param string $surname |
||
125 | * @return void |
||
126 | */ |
||
127 | 2 | public function setSurname($surname) |
|
131 | |||
132 | /** |
||
133 | * @return string |
||
134 | */ |
||
135 | 2 | public function getCertificate() |
|
139 | |||
140 | /** |
||
141 | * @param string $certificate |
||
142 | */ |
||
143 | 2 | public function setCertificate($certificate) |
|
147 | } |
||
148 |
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.