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 |
||
26 | View Code Duplication | class ContactInfo extends Response |
|
|
|||
27 | { |
||
28 | /** |
||
29 | * @var string The Address of Record this contact belongs to. |
||
30 | */ |
||
31 | private $aor; |
||
32 | |||
33 | /** |
||
34 | * @var string The current status of the contact. |
||
35 | */ |
||
36 | private $contactStatus; |
||
37 | |||
38 | /** |
||
39 | * @var string (optional) - Current round trip time, in microseconds, for the contact. |
||
40 | */ |
||
41 | private $roundtripUsec; |
||
42 | |||
43 | /** |
||
44 | * @var string The location of the contact. |
||
45 | */ |
||
46 | private $uri; |
||
47 | |||
48 | /** |
||
49 | * @return string The Address of Record this contact belongs to. |
||
50 | */ |
||
51 | public function getAor() |
||
55 | |||
56 | /** |
||
57 | * @return string The current status of the contact. |
||
58 | */ |
||
59 | public function getContactStatus() |
||
63 | |||
64 | /** |
||
65 | * @return string (optional) - Current round trip time, in microseconds, for the contact. |
||
66 | */ |
||
67 | public function getRoundtripUsec() |
||
71 | |||
72 | /** |
||
73 | * @return string The location of the contact. |
||
74 | */ |
||
75 | public function getUri() |
||
79 | |||
80 | /** |
||
81 | * @param string $response |
||
82 | */ |
||
83 | public function __construct($response) |
||
92 | |||
93 | } |
||
94 |
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.