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 |
||
| 19 | abstract class IncomingContext extends PipelineStageContext implements MessageProcessingContextInterface |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * @var string |
||
| 23 | */ |
||
| 24 | protected $messageId; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var array |
||
| 28 | */ |
||
| 29 | protected $headers; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var IncomingPhysicalMessage |
||
| 33 | */ |
||
| 34 | protected $incomingPhysicalMessage; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var PendingTransportOperations |
||
| 38 | */ |
||
| 39 | protected $pendingTransportOperations; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var BusOperations |
||
| 43 | */ |
||
| 44 | protected $busOperations; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @var OutgoingOptionsFactory |
||
| 48 | */ |
||
| 49 | protected $outgoingOptionsFactory; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @var PipelineFactory |
||
| 53 | */ |
||
| 54 | protected $pipelineFactory; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @var EndpointControlToken |
||
| 58 | */ |
||
| 59 | protected $endpointControlToken; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @param string $messageId |
||
| 63 | * @param array $headers |
||
| 64 | * @param IncomingPhysicalMessage $incomingPhysicalMessage |
||
| 65 | * @param PendingTransportOperations $pendingTransportOperations |
||
| 66 | * @param BusOperations $busOperations |
||
| 67 | * @param OutgoingOptionsFactory $outgoingOptionsFactory |
||
| 68 | * @param EndpointControlToken $endpointControlToken |
||
| 69 | * @param PipelineStageContext $parentContext |
||
| 70 | */ |
||
| 71 | 44 | public function __construct( |
|
| 91 | |||
| 92 | /** |
||
| 93 | * @param object $message |
||
| 94 | * @param SendOptions|null $options |
||
| 95 | */ |
||
| 96 | 4 | public function send($message, SendOptions $options = null) |
|
| 102 | |||
| 103 | /** |
||
| 104 | * @param object $message |
||
| 105 | * @param SendOptions|null $options |
||
| 106 | */ |
||
| 107 | 2 | View Code Duplication | public function sendLocal($message, SendOptions $options = null) |
| 114 | |||
| 115 | /** |
||
| 116 | * @param object $message |
||
| 117 | * @param PublishOptions|null $options |
||
| 118 | */ |
||
| 119 | 2 | public function publish($message, PublishOptions $options = null) |
|
| 125 | |||
| 126 | /** |
||
| 127 | * @param string $messageFqcn |
||
| 128 | * @param SubscribeOptions|null $options |
||
| 129 | */ |
||
| 130 | 2 | public function subscribe($messageFqcn, SubscribeOptions $options = null) |
|
| 136 | |||
| 137 | /** |
||
| 138 | * @param string $messageFqcn |
||
| 139 | * @param UnsubscribeOptions|null $options |
||
| 140 | */ |
||
| 141 | 2 | public function unsubscribe($messageFqcn, UnsubscribeOptions $options = null) |
|
| 147 | |||
| 148 | /** |
||
| 149 | * @param object $message |
||
| 150 | * @param ReplyOptions|null $options |
||
| 151 | */ |
||
| 152 | 2 | public function reply($message, ReplyOptions $options = null) |
|
| 158 | |||
| 159 | /** |
||
| 160 | * @return string |
||
| 161 | */ |
||
| 162 | 4 | public function getMessageId() |
|
| 166 | |||
| 167 | /** |
||
| 168 | * @return array |
||
| 169 | */ |
||
| 170 | 6 | public function getHeaders() |
|
| 174 | |||
| 175 | /** |
||
| 176 | * @param string $name |
||
| 177 | * @param string $value |
||
| 178 | */ |
||
| 179 | 1 | public function setHeader($name, $value) |
|
| 183 | |||
| 184 | /** |
||
| 185 | * @param array $headers |
||
| 186 | */ |
||
| 187 | 1 | public function replaceHeaders(array $headers) |
|
| 191 | |||
| 192 | /** |
||
| 193 | * @return IncomingPhysicalMessage |
||
| 194 | */ |
||
| 195 | 4 | public function getIncomingPhysicalMessage() |
|
| 199 | |||
| 200 | /** |
||
| 201 | * @return PendingTransportOperations |
||
| 202 | */ |
||
| 203 | 4 | public function getPendingTransportOperations() |
|
| 207 | |||
| 208 | /** |
||
| 209 | * @param string $address |
||
| 210 | * |
||
| 211 | * @codeCoverageIgnore |
||
| 212 | */ |
||
| 213 | public function forwardCurrentMessageTo($address) |
||
| 217 | |||
| 218 | /** |
||
| 219 | * It requests an endpoint shutdown to take place after the current attempt of processing this message completes, |
||
| 220 | * regardless of the way it completes (with success or failure/exception). |
||
| 221 | * |
||
| 222 | * It effectively pulls out of listening for more messages on the queue. |
||
| 223 | */ |
||
| 224 | 1 | public function shutdownThisEndpointAfterCurrentMessage() |
|
| 228 | |||
| 229 | /** |
||
| 230 | * @return EndpointControlToken |
||
| 231 | */ |
||
| 232 | 4 | public function getEndpointControlToken() |
|
| 236 | } |
||
| 237 |