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 MobileStatusResult implements ResultInterface |
|
|
|||
10 | { |
||
11 | /** @var string response status */ |
||
12 | private $status; |
||
13 | |||
14 | /** @var string signature id */ |
||
15 | private $signatureId; |
||
16 | |||
17 | /** @var array signed document file */ |
||
18 | private $file = array(); |
||
19 | |||
20 | /** |
||
21 | * Fields expected in response |
||
22 | * @return array |
||
23 | */ |
||
24 | 2 | public function getFields() |
|
25 | { |
||
26 | return [ |
||
27 | 2 | 'status', |
|
28 | 'signature_id', |
||
29 | 'file' |
||
30 | ]; |
||
31 | } |
||
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 | * Gets the value of file. |
||
54 | * @return array |
||
55 | */ |
||
56 | 1 | public function getFile() |
|
60 | |||
61 | /** |
||
62 | * Sets the value of file. |
||
63 | * @param array $file the file |
||
64 | * @return void |
||
65 | */ |
||
66 | 1 | public function setFile($file) |
|
70 | |||
71 | /** |
||
72 | * Gets the value of signatureId. |
||
73 | * @return mixed |
||
74 | */ |
||
75 | public function getSignatureId() |
||
79 | |||
80 | /** |
||
81 | * Sets the value of signatureId. |
||
82 | * @param mixed $signatureId the signature id |
||
83 | * @return void |
||
84 | */ |
||
85 | public function setSignatureId($signatureId) |
||
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.