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 |
||
13 | class Exchange implements RabbitMqObjectInterface |
||
14 | { |
||
15 | /** |
||
16 | * @var Client |
||
17 | */ |
||
18 | private $client; |
||
19 | |||
20 | /** |
||
21 | * Name. |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | private $name; |
||
26 | |||
27 | /** |
||
28 | * Type direct, topic, headers or fanout. |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | private $type; |
||
33 | |||
34 | /** |
||
35 | * Passive. |
||
36 | * |
||
37 | * @var bool |
||
38 | */ |
||
39 | private $passive = false; |
||
40 | |||
41 | /** |
||
42 | * Durable. |
||
43 | * |
||
44 | * @var bool |
||
45 | */ |
||
46 | private $durable = false; |
||
47 | |||
48 | /** |
||
49 | * Auto delete. |
||
50 | * |
||
51 | * @var bool |
||
52 | */ |
||
53 | private $autoDelete = false; |
||
54 | |||
55 | /** |
||
56 | * Internal. |
||
57 | * |
||
58 | * @var bool |
||
59 | */ |
||
60 | private $internal = false; |
||
61 | |||
62 | /** |
||
63 | * No wait. |
||
64 | * |
||
65 | * @var bool |
||
66 | */ |
||
67 | private $nowait = false; |
||
68 | |||
69 | /** |
||
70 | * Arguments. |
||
71 | * |
||
72 | * @var array |
||
73 | */ |
||
74 | private $arguments = null; |
||
75 | |||
76 | /** |
||
77 | * Ticket. |
||
78 | * |
||
79 | * @var int |
||
80 | */ |
||
81 | private $ticket = null; |
||
82 | |||
83 | /** |
||
84 | * Parameter to initialize object only one time. |
||
85 | * |
||
86 | * @var bool |
||
87 | */ |
||
88 | private $init = false; |
||
89 | |||
90 | /** |
||
91 | * Set the to (Binding). |
||
92 | * |
||
93 | * @param Client $to |
||
|
|||
94 | * @param string $name |
||
95 | * @param string $type direct, topic, headers or fanout |
||
96 | */ |
||
97 | public function __construct(Client $client, $name, $type) |
||
107 | |||
108 | /** |
||
109 | * Get the exchange name. |
||
110 | * |
||
111 | * @return string |
||
112 | */ |
||
113 | public function getName() |
||
117 | |||
118 | /** |
||
119 | * Get passive. |
||
120 | * |
||
121 | * @return bool |
||
122 | */ |
||
123 | public function getPassive() |
||
127 | |||
128 | /** |
||
129 | * Set passive. |
||
130 | * |
||
131 | * @param bool $passive |
||
132 | * |
||
133 | * @return Exchange |
||
134 | */ |
||
135 | public function setPassive($passive) |
||
141 | |||
142 | /** |
||
143 | * Get durable. |
||
144 | * |
||
145 | * @return bool |
||
146 | */ |
||
147 | public function getDurable() |
||
151 | |||
152 | /** |
||
153 | * Set durable. |
||
154 | * |
||
155 | * @param bool $durable |
||
156 | * |
||
157 | * @return Exchange |
||
158 | */ |
||
159 | public function setDurable($durable) |
||
165 | |||
166 | /** |
||
167 | * Get autoDelete. |
||
168 | * |
||
169 | * @return bool |
||
170 | */ |
||
171 | public function getAutoDelete() |
||
175 | |||
176 | /** |
||
177 | * Set autoDelete. |
||
178 | * |
||
179 | * @param bool $autoDelete |
||
180 | * |
||
181 | * @return Exchange |
||
182 | */ |
||
183 | public function setAutoDelete($autoDelete) |
||
189 | |||
190 | /** |
||
191 | * Get internal. |
||
192 | * |
||
193 | * @return bool |
||
194 | */ |
||
195 | public function getInternal() |
||
199 | |||
200 | /** |
||
201 | * Set internal. |
||
202 | * |
||
203 | * @param bool $internal |
||
204 | * |
||
205 | * @return Exchange |
||
206 | */ |
||
207 | public function setInternal($internal) |
||
213 | |||
214 | /** |
||
215 | * Get nowait. |
||
216 | * |
||
217 | * @return bool |
||
218 | */ |
||
219 | public function getNowait() |
||
223 | |||
224 | /** |
||
225 | * Set nowait. |
||
226 | * |
||
227 | * @param bool $nowait |
||
228 | * |
||
229 | * @return Exchange |
||
230 | */ |
||
231 | public function setNowait($nowait) |
||
237 | |||
238 | /** |
||
239 | * Get arguments. |
||
240 | * |
||
241 | * @return array |
||
242 | */ |
||
243 | public function getArguments() |
||
247 | |||
248 | /** |
||
249 | * Set arguments. |
||
250 | * |
||
251 | * @param array $arguments |
||
252 | * |
||
253 | * @return Exchange |
||
254 | */ |
||
255 | public function setArguments($arguments) |
||
261 | |||
262 | /** |
||
263 | * Get ticket. |
||
264 | * |
||
265 | * @return int |
||
266 | */ |
||
267 | public function getTicket() |
||
271 | |||
272 | /** |
||
273 | * Set ticket. |
||
274 | * |
||
275 | * @param int $ticket |
||
276 | * |
||
277 | * @return Exchange |
||
278 | */ |
||
279 | public function setTicket($ticket) |
||
285 | |||
286 | public function init(AMQPChannel $amqpChannel) |
||
301 | |||
302 | View Code Duplication | public function publish(Message $message, $routingKey, $mandatory = false, |
|
310 | } |
||
311 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.