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 | class BasicConsume extends Frame |
||
17 | { |
||
18 | /** |
||
19 | * @var int |
||
20 | */ |
||
21 | private $reserved1; |
||
22 | |||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | private $queue; |
||
27 | |||
28 | /** |
||
29 | * @var string |
||
30 | */ |
||
31 | private $consumerTag; |
||
32 | |||
33 | /** |
||
34 | * @var bool |
||
35 | */ |
||
36 | private $noLocal; |
||
37 | |||
38 | /** |
||
39 | * @var bool |
||
40 | */ |
||
41 | private $noAck; |
||
42 | |||
43 | /** |
||
44 | * @var bool |
||
45 | */ |
||
46 | private $exclusive; |
||
47 | |||
48 | /** |
||
49 | * @var bool |
||
50 | */ |
||
51 | private $noWait; |
||
52 | |||
53 | /** |
||
54 | * @var array |
||
55 | */ |
||
56 | private $arguments = []; |
||
57 | |||
58 | /** |
||
59 | * @param int $channel |
||
60 | * @param int $reserved1 |
||
61 | * @param string $queue |
||
62 | * @param string $consumerTag |
||
63 | * @param bool $noLocal |
||
64 | * @param bool $noAck |
||
65 | * @param bool $exclusive |
||
66 | * @param bool $noWait |
||
67 | * @param array $arguments |
||
68 | */ |
||
69 | View Code Duplication | public function __construct($channel, $reserved1, $queue, $consumerTag, $noLocal, $noAck, $exclusive, $noWait, $arguments) |
|
82 | |||
83 | /** |
||
84 | * Reserved1. |
||
85 | * |
||
86 | * @return int |
||
87 | */ |
||
88 | public function getReserved1() |
||
92 | |||
93 | /** |
||
94 | * Queue. |
||
95 | * |
||
96 | * @return string |
||
97 | */ |
||
98 | public function getQueue() |
||
102 | |||
103 | /** |
||
104 | * ConsumerTag. |
||
105 | * |
||
106 | * @return string |
||
107 | */ |
||
108 | public function getConsumerTag() |
||
112 | |||
113 | /** |
||
114 | * NoLocal. |
||
115 | * |
||
116 | * @return bool |
||
117 | */ |
||
118 | public function isNoLocal() |
||
122 | |||
123 | /** |
||
124 | * NoAck. |
||
125 | * |
||
126 | * @return bool |
||
127 | */ |
||
128 | public function isNoAck() |
||
132 | |||
133 | /** |
||
134 | * Request exclusive access. |
||
135 | * |
||
136 | * @return bool |
||
137 | */ |
||
138 | public function isExclusive() |
||
142 | |||
143 | /** |
||
144 | * NoWait. |
||
145 | * |
||
146 | * @return bool |
||
147 | */ |
||
148 | public function isNoWait() |
||
152 | |||
153 | /** |
||
154 | * Arguments for declaration. |
||
155 | * |
||
156 | * @return array |
||
157 | */ |
||
158 | public function getArguments() |
||
162 | |||
163 | /** |
||
164 | * @return string |
||
165 | */ |
||
166 | public function encode() |
||
177 | } |
||
178 |
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.