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 |
||
29 | class Peer extends Resource |
||
30 | { |
||
31 | /** |
||
32 | * @var string (optional) - The IP address of the peer. |
||
33 | */ |
||
34 | private $address; |
||
35 | |||
36 | /** |
||
37 | * @var string (optional) - An optional reason associated with the change in peer_status. |
||
38 | */ |
||
39 | private $cause; |
||
40 | |||
41 | /** |
||
42 | * @var string The current state of the peer. Note that the values of the status are dependent on the underlying peer technology. |
||
43 | */ |
||
44 | private $peerStatus; |
||
45 | |||
46 | /** |
||
47 | * @var string (optional) - The port of the peer. |
||
48 | */ |
||
49 | private $port; |
||
50 | |||
51 | /** |
||
52 | * @var integer (optional) - The last known time the peer was contacted. |
||
53 | */ |
||
54 | private $time; |
||
55 | |||
56 | /** |
||
57 | * @return string (optional) - The IP address of the peer. |
||
58 | */ |
||
59 | public function getAddress() |
||
63 | |||
64 | /** |
||
65 | * @return string (optional) - An optional reason associated with the change in peer_status. |
||
66 | */ |
||
67 | public function getCause() |
||
71 | |||
72 | /** |
||
73 | * @return string The current state of the peer. Note that the values of the status are dependent on the underlying peer technology. |
||
74 | */ |
||
75 | public function getPeerStatus() |
||
79 | |||
80 | /** |
||
81 | * @return string (optional) - The port of the peer. |
||
82 | */ |
||
83 | public function getPort() |
||
87 | |||
88 | /** |
||
89 | * @return integer (optional) - The last known time the peer was contacted. |
||
90 | */ |
||
91 | public function getTime() |
||
95 | |||
96 | /** |
||
97 | * @param AriClient $client |
||
98 | * @param string $response |
||
99 | */ |
||
100 | View Code Duplication | public function __construct(AriClient $client, $response) |
|
110 | |||
111 | } |
||
112 |
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.