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 |
||
8 | class Event |
||
9 | { |
||
10 | const MESSAGE_ACKNOWLEDGE = 'message.acknowledge'; |
||
11 | const MESSAGE_FINISH = 'message.finish'; |
||
12 | const MESSAGE_REJECT = 'message.reject'; |
||
13 | |||
14 | /** |
||
15 | * @var EmitterInterface |
||
16 | */ |
||
17 | private $emitter; |
||
18 | |||
19 | /** |
||
20 | * @param EmitterInterface $emitter |
||
21 | */ |
||
22 | 3 | public function __construct(EmitterInterface $emitter) |
|
26 | |||
27 | /** |
||
28 | * Emits message acknowledgement events |
||
29 | * |
||
30 | * @param AbstractOptions $options |
||
31 | */ |
||
32 | View Code Duplication | public function acknowledge(AbstractOptions $options) |
|
41 | |||
42 | /** |
||
43 | * Emits message finished events |
||
44 | * |
||
45 | * @param AbstractOptions $options |
||
46 | */ |
||
47 | View Code Duplication | public function finish(AbstractOptions $options) |
|
56 | |||
57 | /** |
||
58 | * Emits message rejection events |
||
59 | * |
||
60 | * @param AbstractOptions $options |
||
61 | * @param Exception $exception |
||
62 | */ |
||
63 | View Code Duplication | public function reject(AbstractOptions $options, Exception $exception) |
|
72 | } |
||
73 |
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.