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 |
||
8 | class WorkerQueueBag implements QueueBagInterface |
||
9 | { |
||
10 | private $resolver; |
||
11 | private $options; |
||
12 | |||
13 | public function __construct( |
||
26 | |||
27 | /** |
||
28 | * @param $queue |
||
29 | */ |
||
30 | public function setQueue($queue) |
||
34 | |||
35 | /** |
||
36 | * @return string|mixed |
||
37 | */ |
||
38 | public function getQueue() |
||
42 | |||
43 | /** |
||
44 | * @param $qos |
||
45 | */ |
||
46 | public function setBasicQos($qos) |
||
50 | |||
51 | /** |
||
52 | * @return int |
||
53 | */ |
||
54 | public function getBasicQos() |
||
58 | |||
59 | /** |
||
60 | * @return bool |
||
61 | */ |
||
62 | public function getPassive() |
||
66 | |||
67 | /** |
||
68 | * @return bool |
||
69 | */ |
||
70 | public function getDurable() |
||
74 | |||
75 | /** |
||
76 | * @return bool |
||
77 | */ |
||
78 | public function getExclusive() |
||
82 | |||
83 | /** |
||
84 | * @return bool |
||
85 | */ |
||
86 | public function getAutoDelete() |
||
90 | |||
91 | /** |
||
92 | * @return bool |
||
93 | */ |
||
94 | public function getNoWait() |
||
98 | |||
99 | /** |
||
100 | * @return null |
||
101 | */ |
||
102 | public function getTicket() |
||
106 | |||
107 | /** |
||
108 | * @return string |
||
109 | */ |
||
110 | public function getConsumerTag() |
||
114 | |||
115 | /** |
||
116 | * @return bool |
||
117 | */ |
||
118 | public function getNoAck() |
||
122 | |||
123 | /** |
||
124 | * @return bool |
||
125 | */ |
||
126 | public function getNoLocal() |
||
130 | |||
131 | /** |
||
132 | * @param array $arguments |
||
133 | */ |
||
134 | public function setArguments(array $arguments) |
||
138 | |||
139 | /** |
||
140 | * @return string |
||
141 | */ |
||
142 | public function getArguments() |
||
146 | |||
147 | /** |
||
148 | * @return array |
||
149 | */ |
||
150 | View Code Duplication | public function getQueueDeclare() |
|
163 | |||
164 | /** |
||
165 | * @return array |
||
166 | */ |
||
167 | View Code Duplication | public function getQueueConsume() |
|
180 | |||
181 | /** |
||
182 | * @return array|false |
||
183 | */ |
||
184 | public function getExchangeDeclare() |
||
188 | |||
189 | /** |
||
190 | * @return string |
||
191 | */ |
||
192 | public function getExchange() |
||
196 | |||
197 | /** |
||
198 | * @return string |
||
199 | */ |
||
200 | public function getType() |
||
204 | |||
205 | /** |
||
206 | * @param array $options |
||
207 | * @return QueueBagInterface |
||
208 | */ |
||
209 | public function registerOptions(array $options) |
||
215 | } |
||
216 |
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.