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 |
||
16 | View Code Duplication | class ExchangeUnbind extends Frame |
|
|
|||
17 | { |
||
18 | /** |
||
19 | * @var int |
||
20 | */ |
||
21 | private $reserved1; |
||
22 | |||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | private $destination; |
||
27 | |||
28 | /** |
||
29 | * @var string |
||
30 | */ |
||
31 | private $source; |
||
32 | |||
33 | /** |
||
34 | * @var string |
||
35 | */ |
||
36 | private $routingKey; |
||
37 | |||
38 | /** |
||
39 | * @var bool |
||
40 | */ |
||
41 | private $noWait; |
||
42 | |||
43 | /** |
||
44 | * @var array |
||
45 | */ |
||
46 | private $arguments = []; |
||
47 | |||
48 | /** |
||
49 | * @param int $channel |
||
50 | * @param int $reserved1 |
||
51 | * @param string $destination |
||
52 | * @param string $source |
||
53 | * @param string $routingKey |
||
54 | * @param bool $noWait |
||
55 | * @param array $arguments |
||
56 | */ |
||
57 | public function __construct($channel, $reserved1, $destination, $source, $routingKey, $noWait, $arguments) |
||
68 | |||
69 | /** |
||
70 | * Reserved1. |
||
71 | * |
||
72 | * @return int |
||
73 | */ |
||
74 | public function getReserved1() |
||
78 | |||
79 | /** |
||
80 | * Destination. |
||
81 | * |
||
82 | * @return string |
||
83 | */ |
||
84 | public function getDestination() |
||
88 | |||
89 | /** |
||
90 | * Source. |
||
91 | * |
||
92 | * @return string |
||
93 | */ |
||
94 | public function getSource() |
||
98 | |||
99 | /** |
||
100 | * Routing key of binding. |
||
101 | * |
||
102 | * @return string |
||
103 | */ |
||
104 | public function getRoutingKey() |
||
108 | |||
109 | /** |
||
110 | * NoWait. |
||
111 | * |
||
112 | * @return bool |
||
113 | */ |
||
114 | public function isNoWait() |
||
118 | |||
119 | /** |
||
120 | * Arguments of binding. |
||
121 | * |
||
122 | * @return array |
||
123 | */ |
||
124 | public function getArguments() |
||
128 | |||
129 | /** |
||
130 | * @return string |
||
131 | */ |
||
132 | public function encode() |
||
144 | } |
||
145 |
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.