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 |
||
11 | class SimpleStompMessageProvider implements MessageProviderInterface |
||
12 | { |
||
13 | /** |
||
14 | * @var Client |
||
15 | */ |
||
16 | private $client; |
||
17 | |||
18 | /** |
||
19 | * @var SimpleStomp |
||
20 | */ |
||
21 | private $stomp; |
||
22 | |||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | private $destination; |
||
27 | |||
28 | /** |
||
29 | * @param Client $client |
||
30 | * @param string $destination |
||
31 | * @param null $subscriptionId |
||
32 | * @param string $ack |
||
33 | * @param null $selector |
||
34 | * @param array $header |
||
35 | */ |
||
36 | View Code Duplication | public function __construct( |
|
50 | |||
51 | View Code Duplication | public function get() |
|
59 | |||
60 | /** |
||
61 | * @param Message $message |
||
62 | */ |
||
63 | public function ack(Message $message) |
||
67 | |||
68 | /** |
||
69 | * @param Message $message |
||
70 | * @param bool $requeue |
||
71 | * |
||
72 | * @throws StompException |
||
73 | */ |
||
74 | public function nack(Message $message, $requeue = false) |
||
90 | |||
91 | /** |
||
92 | * @return string |
||
93 | */ |
||
94 | public function getQueueName() |
||
98 | } |
||
99 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.