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 SubscriberQueueBag implements QueueBagInterface |
||
9 | { |
||
10 | private $resolver; |
||
11 | private $options; |
||
12 | |||
13 | View Code Duplication | public function __construct( |
|
30 | |||
31 | /** |
||
32 | * @param $exchange |
||
33 | */ |
||
34 | public function setExchange($exchange) |
||
38 | |||
39 | /** |
||
40 | * @return string|mixed |
||
41 | */ |
||
42 | public function getExchange() |
||
46 | |||
47 | /** |
||
48 | * @param $qos |
||
49 | */ |
||
50 | public function setBasicQos($qos) |
||
54 | |||
55 | /** |
||
56 | * @return int |
||
57 | */ |
||
58 | public function getBasicQos() |
||
62 | |||
63 | /** |
||
64 | * @param $queueName |
||
65 | */ |
||
66 | public function setQueue($queueName) |
||
70 | |||
71 | |||
72 | /** |
||
73 | * @return string|mixed |
||
74 | */ |
||
75 | public function getQueue() |
||
79 | |||
80 | /** |
||
81 | * @param $type |
||
82 | */ |
||
83 | public function setType($type) |
||
87 | |||
88 | /** |
||
89 | * @return string |
||
90 | */ |
||
91 | public function getType() |
||
95 | |||
96 | /** |
||
97 | * @return bool |
||
98 | */ |
||
99 | public function getPassive() |
||
103 | |||
104 | /** |
||
105 | * @param $internal |
||
106 | */ |
||
107 | public function setInternal($internal) |
||
111 | |||
112 | /** |
||
113 | * @param array $arguments |
||
114 | */ |
||
115 | public function setArguments(array $arguments) |
||
119 | |||
120 | /** |
||
121 | * @return string |
||
122 | */ |
||
123 | public function getArguments() |
||
127 | |||
128 | /** |
||
129 | * @return bool |
||
130 | */ |
||
131 | public function getInternal() |
||
135 | |||
136 | /** |
||
137 | * @return bool |
||
138 | */ |
||
139 | public function getDurable() |
||
143 | |||
144 | /** |
||
145 | * @return bool |
||
146 | */ |
||
147 | public function getAutoDelete() |
||
151 | |||
152 | |||
153 | /** |
||
154 | * @return string |
||
155 | */ |
||
156 | public function getTicket() |
||
160 | |||
161 | /** |
||
162 | * @return bool |
||
163 | */ |
||
164 | public function getNoAck() |
||
168 | |||
169 | /** |
||
170 | * @return bool |
||
171 | */ |
||
172 | public function getNoLocal() |
||
176 | |||
177 | /** |
||
178 | * @return bool |
||
179 | */ |
||
180 | public function getNoWait() |
||
184 | |||
185 | /** |
||
186 | * @return bool |
||
187 | */ |
||
188 | public function getExclusive() |
||
192 | |||
193 | /** |
||
194 | * @return string |
||
195 | */ |
||
196 | public function getConsumerTag() |
||
200 | |||
201 | /** |
||
202 | * @return array |
||
203 | */ |
||
204 | View Code Duplication | public function getQueueDeclare() |
|
217 | |||
218 | /** |
||
219 | * @return array |
||
220 | */ |
||
221 | View Code Duplication | public function getQueueConsume() |
|
234 | |||
235 | public function getExchangeDeclare() |
||
249 | |||
250 | /** |
||
251 | * @param array $options |
||
252 | * @return QueueBagInterface |
||
253 | */ |
||
254 | public function registerOptions(array $options) |
||
258 | } |
||
259 |
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.