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 |
||
14 | class BusOperations |
||
15 | { |
||
16 | /** |
||
17 | * @var PipelineFactory |
||
18 | */ |
||
19 | private $pipelineFactory; |
||
20 | |||
21 | /** |
||
22 | * @var BusOperationsContextFactory |
||
23 | */ |
||
24 | private $busOperationsContextFactory; |
||
25 | |||
26 | /** |
||
27 | * @var PipelineModifications |
||
28 | */ |
||
29 | private $pipelineModifications; |
||
30 | |||
31 | /** |
||
32 | * @var UuidGeneratorInterface |
||
33 | */ |
||
34 | private $uuidGenerator; |
||
35 | |||
36 | /** |
||
37 | * @param PipelineFactory $pipelineFactory |
||
38 | * @param BusOperationsContextFactory $busOperationsContextFactory |
||
39 | * @param PipelineModifications $pipelineModifications |
||
40 | * @param UuidGeneratorInterface $uuidGenerator |
||
41 | */ |
||
42 | 10 | public function __construct( |
|
53 | |||
54 | /** |
||
55 | * @param object $message |
||
56 | * @param SendOptions $options |
||
57 | * @param PipelineStageContext $parentContext |
||
58 | */ |
||
59 | 3 | View Code Duplication | public function send($message, SendOptions $options, PipelineStageContext $parentContext) |
67 | |||
68 | /** |
||
69 | * @param object $message |
||
70 | * @param SendOptions $options |
||
71 | * @param PipelineStageContext $parentContext |
||
72 | */ |
||
73 | 1 | public function sendLocal($message, SendOptions $options, PipelineStageContext $parentContext) |
|
79 | |||
80 | /** |
||
81 | * @param object $message |
||
82 | * @param PublishOptions $options |
||
83 | * @param PipelineStageContext $parentContext |
||
84 | */ |
||
85 | 2 | View Code Duplication | public function publish($message, PublishOptions $options, PipelineStageContext $parentContext) |
96 | |||
97 | /** |
||
98 | * @param object $message |
||
99 | * @param ReplyOptions $options |
||
100 | * @param IncomingContext $parentContext |
||
101 | */ |
||
102 | 2 | View Code Duplication | public function reply($message, ReplyOptions $options, IncomingContext $parentContext) |
113 | |||
114 | /** |
||
115 | * @param string $eventFqcn |
||
116 | * @param SubscribeOptions $options |
||
117 | * @param PipelineStageContext $parentContext |
||
118 | */ |
||
119 | 1 | View Code Duplication | public function subscribe($eventFqcn, SubscribeOptions $options, PipelineStageContext $parentContext) |
133 | |||
134 | /** |
||
135 | * @param string $eventFqcn |
||
136 | * @param UnsubscribeOptions $options |
||
137 | * @param PipelineStageContext $parentContext |
||
138 | */ |
||
139 | 1 | View Code Duplication | public function unsubscribe($eventFqcn, UnsubscribeOptions $options, PipelineStageContext $parentContext) |
153 | |||
154 | /** |
||
155 | * @param OutgoingOptions $options |
||
156 | */ |
||
157 | 7 | private function ensureMessageId(OutgoingOptions $options) |
|
163 | } |
||
164 |