Complex classes like Queue often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Queue, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
13 | class Queue implements RabbitMqObjectInterface |
||
14 | { |
||
15 | /** |
||
16 | * @var Client |
||
17 | */ |
||
18 | private $client; |
||
19 | |||
20 | /** |
||
21 | * @var Binding |
||
22 | */ |
||
23 | private $source; |
||
24 | |||
25 | /** |
||
26 | * Queue name. |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | private $name; |
||
31 | |||
32 | /** |
||
33 | * Queue. |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | private $queue = ''; |
||
|
|||
38 | |||
39 | /** |
||
40 | * Passive. |
||
41 | * |
||
42 | * @var bool |
||
43 | */ |
||
44 | private $passive = false; |
||
45 | |||
46 | /** |
||
47 | * Durable. |
||
48 | * |
||
49 | * @var bool |
||
50 | */ |
||
51 | private $durable = false; |
||
52 | |||
53 | /** |
||
54 | * Exclusive. |
||
55 | * |
||
56 | * @var bool |
||
57 | */ |
||
58 | private $exclusive = false; |
||
59 | |||
60 | /** |
||
61 | * Auto delete. |
||
62 | * |
||
63 | * @var bool |
||
64 | */ |
||
65 | private $autoDelete = false; |
||
66 | |||
67 | /** |
||
68 | * No wait. |
||
69 | * |
||
70 | * @var bool |
||
71 | */ |
||
72 | private $noWait = false; |
||
73 | |||
74 | /** |
||
75 | * Ticket. |
||
76 | * |
||
77 | * @var int |
||
78 | */ |
||
79 | private $ticket = null; |
||
80 | |||
81 | /** |
||
82 | *R abbitMq specific parameter : x-dead-letter-exchange. |
||
83 | * |
||
84 | * @var Queue |
||
85 | */ |
||
86 | private $deadLetterQueue = null; |
||
87 | |||
88 | /** |
||
89 | * RabbitMq specific parameter : confirm. |
||
90 | * |
||
91 | * @var int |
||
92 | */ |
||
93 | private $confirm = null; |
||
94 | |||
95 | /** |
||
96 | * RabbitMq specific parameter : consumer_cancel_notify. |
||
97 | * |
||
98 | * @var bool |
||
99 | */ |
||
100 | private $consumerCancelNotify = null; |
||
101 | |||
102 | /** |
||
103 | * RabbitMq specific parameter : alternate-exchange. |
||
104 | * |
||
105 | * @var Queue |
||
106 | */ |
||
107 | private $alternateExchange = null; |
||
108 | |||
109 | /** |
||
110 | * RabbitMq specific parameter : x-message-ttl. |
||
111 | * |
||
112 | * @var int |
||
113 | */ |
||
114 | private $ttl = null; |
||
115 | |||
116 | /** |
||
117 | * RabbitMq specific parameter : x-max-length. |
||
118 | * |
||
119 | * @var int |
||
120 | */ |
||
121 | private $maxLength = null; |
||
122 | |||
123 | /** |
||
124 | * RabbitMq specific parameter : x-max-priority. |
||
125 | * |
||
126 | * @var int |
||
127 | */ |
||
128 | private $maxPriority = null; |
||
129 | |||
130 | /** |
||
131 | * Parameter to initialize object only one time. |
||
132 | * |
||
133 | * @var bool |
||
134 | */ |
||
135 | private $init = false; |
||
136 | |||
137 | /** |
||
138 | * Consumer list implement ConsumerInterface. |
||
139 | * |
||
140 | * @var array|null |
||
141 | */ |
||
142 | private $consumers; |
||
143 | |||
144 | /** |
||
145 | * Set the source (Binding). |
||
146 | * |
||
147 | * @param Binding $source |
||
148 | * @param string $name |
||
149 | * @param ConsumerInterface[] $consumers |
||
150 | */ |
||
151 | public function __contruct(Client $client, Binding $source, $name, array $consumers = []) |
||
158 | |||
159 | /** |
||
160 | * Get queue name. |
||
161 | * |
||
162 | * @return string |
||
163 | */ |
||
164 | public function getName() |
||
168 | |||
169 | /** |
||
170 | * Get passive. |
||
171 | * |
||
172 | * @return bool |
||
173 | */ |
||
174 | public function getPassive() |
||
178 | |||
179 | /** |
||
180 | * @param bool $passive |
||
181 | * |
||
182 | * @return Queue |
||
183 | */ |
||
184 | public function setPassive($passive) |
||
190 | |||
191 | /** |
||
192 | * Get durable. |
||
193 | * |
||
194 | * @return bool |
||
195 | */ |
||
196 | public function getDurable() |
||
200 | |||
201 | /** |
||
202 | * Set durable. |
||
203 | * |
||
204 | * @param bool $durable |
||
205 | * |
||
206 | * @return Queue |
||
207 | */ |
||
208 | public function setDurable($durable) |
||
214 | |||
215 | /** |
||
216 | * Get exclusive. |
||
217 | * |
||
218 | * @return bool |
||
219 | */ |
||
220 | public function getExclusive() |
||
224 | |||
225 | /** |
||
226 | * Set exclusive. |
||
227 | * |
||
228 | * @param bool $exclusive |
||
229 | * |
||
230 | * @return Queue |
||
231 | */ |
||
232 | public function setExclusive($exclusive) |
||
238 | |||
239 | /** |
||
240 | * Get autoDelete. |
||
241 | * |
||
242 | * @return bool |
||
243 | */ |
||
244 | public function getAutoDelete() |
||
248 | |||
249 | /** |
||
250 | * Set autoDelete. |
||
251 | * |
||
252 | * @param bool $autoDelete |
||
253 | * |
||
254 | * @return Queue |
||
255 | */ |
||
256 | public function setAutoDelete($autoDelete) |
||
262 | |||
263 | /** |
||
264 | * Get noWait. |
||
265 | * |
||
266 | * @return bool |
||
267 | */ |
||
268 | public function getNoWait() |
||
272 | |||
273 | /** |
||
274 | * Set noWait. |
||
275 | * |
||
276 | * @param bool $noWait |
||
277 | * |
||
278 | * @return Queue |
||
279 | */ |
||
280 | public function setNoWait($noWait) |
||
286 | |||
287 | /** |
||
288 | * Get arguments. |
||
289 | * |
||
290 | * @return array|null |
||
291 | */ |
||
292 | public function getArguments() |
||
296 | |||
297 | /** |
||
298 | * Set arguments. |
||
299 | * |
||
300 | * @param array $arguments |
||
301 | * |
||
302 | * @return Queue |
||
303 | */ |
||
304 | public function setArguments($arguments) |
||
310 | |||
311 | /** |
||
312 | * Get ticket. |
||
313 | * |
||
314 | * @return int |
||
315 | */ |
||
316 | public function getTicket() |
||
320 | |||
321 | /** |
||
322 | * Set ticket. |
||
323 | * |
||
324 | * @param int $ticket |
||
325 | * |
||
326 | * @return Queue |
||
327 | */ |
||
328 | public function setTicket($ticket) |
||
334 | |||
335 | /** |
||
336 | * Get RabbitMq specific parameter : dead letter queue. |
||
337 | * |
||
338 | * @return Queue |
||
339 | */ |
||
340 | public function getDeadLetterQueue() |
||
344 | |||
345 | /** |
||
346 | * Set RabbitMq specific parameter : dead letter queue. |
||
347 | * |
||
348 | * @param Queue $queue |
||
349 | * |
||
350 | * @return Queue |
||
351 | */ |
||
352 | public function setDeadLetterQueue(Queue $queue) |
||
358 | |||
359 | /** |
||
360 | * Get RabbitMq specific parameter : confirm. |
||
361 | * |
||
362 | * @return int |
||
363 | */ |
||
364 | public function getConfirm() |
||
368 | |||
369 | /** |
||
370 | * Set RabbitMq specific parameter : confirm. |
||
371 | * |
||
372 | * @param int $confirm |
||
373 | * |
||
374 | * @return Queue |
||
375 | */ |
||
376 | public function setConfirm($confirm) |
||
382 | |||
383 | /** |
||
384 | * Get RabbitMq specific parameter : consumer_cancel_notify. |
||
385 | * |
||
386 | * @return bool |
||
387 | */ |
||
388 | public function getConsumerCancelNotify() |
||
392 | |||
393 | /** |
||
394 | * Set RabbitMq specific parameter : consumer_cancel_notify. |
||
395 | * |
||
396 | * @param Queue $consumerCancelNotify |
||
397 | * |
||
398 | * @return Queue |
||
399 | */ |
||
400 | public function setConsumerCancelNotify(Queue $consumerCancelNotify) |
||
406 | |||
407 | /** |
||
408 | * Get RabbitMq specific parameter : alternate_exchange. |
||
409 | * |
||
410 | * @return Queue |
||
411 | */ |
||
412 | public function getAlternateExchange() |
||
416 | |||
417 | /** |
||
418 | * Set RabbitMq specific parameter : alternate_exchange. |
||
419 | * |
||
420 | * @param Queue $alternateExchange |
||
421 | * |
||
422 | * @return Queue |
||
423 | */ |
||
424 | public function setAlternateExchange(Queue $alternateExchange) |
||
430 | |||
431 | /** |
||
432 | * Get RabbitMq specific parameter : ttl. |
||
433 | * |
||
434 | * @return int |
||
435 | */ |
||
436 | public function getTtl() |
||
440 | |||
441 | /** |
||
442 | * Set RabbitMq specific parameter : ttl. |
||
443 | * |
||
444 | * @param int $ttl |
||
445 | * |
||
446 | * @return Queue |
||
447 | */ |
||
448 | public function setTtl($ttl) |
||
454 | |||
455 | /** |
||
456 | * Get RabbitMq specific parameter : max length. |
||
457 | * |
||
458 | * @return int |
||
459 | */ |
||
460 | public function getMaxLength() |
||
464 | |||
465 | /** |
||
466 | * Set RabbitMq specific parameter : max length. |
||
467 | * |
||
468 | * @param int $ttl |
||
469 | * |
||
470 | * @return Queue |
||
471 | */ |
||
472 | public function setMaxLength($maxLength) |
||
478 | |||
479 | /** |
||
480 | * Get RabbitMq specific parameter : max priority. |
||
481 | * |
||
482 | * @return int |
||
483 | */ |
||
484 | public function getMaxPriority() |
||
488 | |||
489 | /** |
||
490 | * Set RabbitMq specific parameter : max priority. |
||
491 | * |
||
492 | * @param int $maxPriority |
||
493 | * |
||
494 | * @return Queue |
||
495 | */ |
||
496 | public function setMaxPriority($maxPriority) |
||
502 | |||
503 | public function init(AMQPChannel $amqpChannel) |
||
539 | |||
540 | public function consume() |
||
557 | } |
||
558 |
This check marks private properties in classes that are never used. Those properties can be removed.