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 |
||
| 11 | class Queue implements RabbitMqObjectInterface{ |
||
| 12 | |||
| 13 | /** |
||
| 14 | * |
||
| 15 | * @var Binding |
||
| 16 | */ |
||
| 17 | private $source; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Queue name |
||
| 21 | * @var String |
||
| 22 | */ |
||
| 23 | private $name; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Queue |
||
| 27 | * @var string |
||
| 28 | */ |
||
| 29 | private $queue = ''; |
||
|
|
|||
| 30 | |||
| 31 | /** |
||
| 32 | * Passive |
||
| 33 | * @var bool |
||
| 34 | */ |
||
| 35 | private $passive = false; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Durable |
||
| 39 | * @var bool |
||
| 40 | */ |
||
| 41 | private $durable = false; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Exclusive |
||
| 45 | * @var bool |
||
| 46 | */ |
||
| 47 | private $exclusive = false; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Auto delete |
||
| 51 | * @var bool |
||
| 52 | */ |
||
| 53 | private $autoDelete = false; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * No wait |
||
| 57 | * @var bool |
||
| 58 | */ |
||
| 59 | private $autoDelete = false; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Ticket |
||
| 63 | * @var int |
||
| 64 | */ |
||
| 65 | private $ticket = null; |
||
| 66 | |||
| 67 | /** |
||
| 68 | *R abbitMq specific parameter : x-dead-letter-exchange |
||
| 69 | * @var Queue |
||
| 70 | */ |
||
| 71 | private $deadLetterQueue = null; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * RabbitMq specific parameter : confirm |
||
| 75 | * @var int |
||
| 76 | */ |
||
| 77 | private $confirm = null; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * RabbitMq specific parameter : consumer_cancel_notify |
||
| 81 | * @var bool |
||
| 82 | */ |
||
| 83 | private $consumerCancelNotify = null; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * RabbitMq specific parameter : alternate-exchange |
||
| 87 | * @var Queue |
||
| 88 | */ |
||
| 89 | private $alternateExchange = null; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * RabbitMq specific parameter : x-message-ttl |
||
| 93 | * @var int |
||
| 94 | */ |
||
| 95 | private $ttl = null; |
||
| 96 | |||
| 97 | /** |
||
| 98 | * RabbitMq specific parameter : x-max-length |
||
| 99 | * @var int |
||
| 100 | */ |
||
| 101 | private $maxLength = null; |
||
| 102 | |||
| 103 | /** |
||
| 104 | * RabbitMq specific parameter : x-max-priority |
||
| 105 | * @var int |
||
| 106 | */ |
||
| 107 | private $maxPriority = null; |
||
| 108 | |||
| 109 | /** |
||
| 110 | * Parameter to initialize object only one time |
||
| 111 | * @var bool |
||
| 112 | */ |
||
| 113 | private $init = false; |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Set the source (Binding) |
||
| 117 | * @param Binding $source |
||
| 118 | * @param string $name |
||
| 119 | */ |
||
| 120 | public function __contruct(Binding $source, $name) { |
||
| 124 | |||
| 125 | /** |
||
| 126 | * Get queue name |
||
| 127 | * @return string |
||
| 128 | */ |
||
| 129 | public function getName() { |
||
| 132 | |||
| 133 | /** |
||
| 134 | * Get passive |
||
| 135 | * @return bool |
||
| 136 | */ |
||
| 137 | public function getPassive() { |
||
| 140 | |||
| 141 | /** |
||
| 142 | * |
||
| 143 | * @param bool $passive |
||
| 144 | * @return Queue |
||
| 145 | */ |
||
| 146 | public function setPassive($passive) { |
||
| 150 | |||
| 151 | /** |
||
| 152 | * Get durable |
||
| 153 | * @return bool |
||
| 154 | */ |
||
| 155 | public function getDurable() { |
||
| 158 | |||
| 159 | /** |
||
| 160 | * Set durable |
||
| 161 | * @param bool $durable |
||
| 162 | * @return Queue |
||
| 163 | */ |
||
| 164 | public function setDurable($durable) { |
||
| 168 | |||
| 169 | /** |
||
| 170 | * Get exclusive |
||
| 171 | * @return bool |
||
| 172 | */ |
||
| 173 | public function getExclusive() { |
||
| 176 | |||
| 177 | /** |
||
| 178 | * Set exclusive |
||
| 179 | * @param bool $exclusive |
||
| 180 | * @return Queue |
||
| 181 | */ |
||
| 182 | public function setExclusive($exclusive) { |
||
| 186 | |||
| 187 | /** |
||
| 188 | * Get autoDelete |
||
| 189 | * @return bool |
||
| 190 | */ |
||
| 191 | public function getAutoDelete() { |
||
| 194 | |||
| 195 | /** |
||
| 196 | * Set autoDelete |
||
| 197 | * @param bool $autoDelete |
||
| 198 | * @return Queue |
||
| 199 | */ |
||
| 200 | public function setAutoDelete($autoDelete) { |
||
| 204 | |||
| 205 | /** |
||
| 206 | * Get noWait |
||
| 207 | * @return bool |
||
| 208 | */ |
||
| 209 | public function getNoWait() { |
||
| 212 | |||
| 213 | /** |
||
| 214 | * Set noWait |
||
| 215 | * @param bool $noWait |
||
| 216 | * @return Queue |
||
| 217 | */ |
||
| 218 | public function setNoWait($noWait) { |
||
| 222 | |||
| 223 | /** |
||
| 224 | * Get arguments |
||
| 225 | * @return array|null |
||
| 226 | */ |
||
| 227 | public function getArguments() { |
||
| 230 | |||
| 231 | /** |
||
| 232 | * Set arguments |
||
| 233 | * @param array $arguments |
||
| 234 | * @return Queue |
||
| 235 | */ |
||
| 236 | public function setArguments($arguments) { |
||
| 240 | |||
| 241 | /** |
||
| 242 | * Get ticket |
||
| 243 | * @return int |
||
| 244 | */ |
||
| 245 | public function getTicket() { |
||
| 248 | |||
| 249 | /** |
||
| 250 | * Set ticket |
||
| 251 | * @param int $ticket |
||
| 252 | * @return Queue |
||
| 253 | */ |
||
| 254 | public function setTicket($ticket) { |
||
| 258 | |||
| 259 | /** |
||
| 260 | * Get RabbitMq specific parameter : dead letter queue |
||
| 261 | * @return Queue |
||
| 262 | */ |
||
| 263 | public function getDeadLetterQueue() { |
||
| 266 | |||
| 267 | /** |
||
| 268 | * Set RabbitMq specific parameter : dead letter queue |
||
| 269 | * @param Queue $queue |
||
| 270 | * @return Queue |
||
| 271 | */ |
||
| 272 | public function setDeadLetterQueue(Queue $queue) { |
||
| 276 | |||
| 277 | /** |
||
| 278 | * Get RabbitMq specific parameter : confirm |
||
| 279 | * @return int |
||
| 280 | */ |
||
| 281 | public function getConfirm() { |
||
| 284 | |||
| 285 | /** |
||
| 286 | * Set RabbitMq specific parameter : confirm |
||
| 287 | * @param int $confirm |
||
| 288 | * @return Queue |
||
| 289 | */ |
||
| 290 | public function setConfirm($confirm) { |
||
| 294 | |||
| 295 | /** |
||
| 296 | * Get RabbitMq specific parameter : consumer_cancel_notify |
||
| 297 | * @return bool |
||
| 298 | */ |
||
| 299 | public function getConsumerCancelNotify() { |
||
| 302 | |||
| 303 | /** |
||
| 304 | * Set RabbitMq specific parameter : consumer_cancel_notify |
||
| 305 | * @param Queue $consumerCancelNotify |
||
| 306 | * @return Queue |
||
| 307 | */ |
||
| 308 | public function setConsumerCancelNotify(Queue $consumerCancelNotify) { |
||
| 312 | |||
| 313 | /** |
||
| 314 | * Get RabbitMq specific parameter : alternate_exchange |
||
| 315 | * @return Queue |
||
| 316 | */ |
||
| 317 | public function getAlternateExchange() { |
||
| 320 | |||
| 321 | /** |
||
| 322 | * Set RabbitMq specific parameter : alternate_exchange |
||
| 323 | * @param Queue $alternateExchange |
||
| 324 | * @return Queue |
||
| 325 | */ |
||
| 326 | public function setAlternateExchange(Queue $alternateExchange) { |
||
| 330 | |||
| 331 | /** |
||
| 332 | * Get RabbitMq specific parameter : ttl |
||
| 333 | * @return int |
||
| 334 | */ |
||
| 335 | public function getTtl() { |
||
| 338 | |||
| 339 | /** |
||
| 340 | * Set RabbitMq specific parameter : ttl |
||
| 341 | * @param int $ttl |
||
| 342 | * @return Queue |
||
| 343 | */ |
||
| 344 | public function setTtl($ttl) { |
||
| 348 | |||
| 349 | /** |
||
| 350 | * Get RabbitMq specific parameter : max length |
||
| 351 | * @return int |
||
| 352 | */ |
||
| 353 | public function getMaxLength() { |
||
| 356 | |||
| 357 | /** |
||
| 358 | * Set RabbitMq specific parameter : max length |
||
| 359 | * @param int $ttl |
||
| 360 | * @return Queue |
||
| 361 | */ |
||
| 362 | public function setMaxLength($maxLength) { |
||
| 366 | |||
| 367 | /** |
||
| 368 | * Get RabbitMq specific parameter : max priority |
||
| 369 | * @return int |
||
| 370 | */ |
||
| 371 | public function getMaxPriority() { |
||
| 374 | |||
| 375 | /** |
||
| 376 | * Set RabbitMq specific parameter : max priority |
||
| 377 | * @param int $maxPriority |
||
| 378 | * @return Queue |
||
| 379 | */ |
||
| 380 | public function setMaxPriority($maxPriority) { |
||
| 384 | |||
| 385 | |||
| 386 | public function init(AMQPChannel $amqpChannel) { |
||
| 422 | |||
| 423 | |||
| 424 | public function comsume() { |
||
| 427 | } |
This check marks private properties in classes that are never used. Those properties can be removed.