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 |
||
17 | View Code Duplication | class PredisUniqueEventQueue implements EventQueueInterface |
|
1 ignored issue
–
show
|
|||
18 | { |
||
19 | const SET_KEY = 'unique_events'; |
||
20 | const FORMAT = 'predis'; |
||
21 | |||
22 | /** |
||
23 | * @var Client |
||
24 | */ |
||
25 | private $client; |
||
26 | |||
27 | /** |
||
28 | * @var Serializer |
||
29 | */ |
||
30 | private $serializer; |
||
31 | |||
32 | /** |
||
33 | * @var LoggerInterface |
||
34 | */ |
||
35 | private $logger; |
||
36 | |||
37 | /** |
||
38 | * @param Client $client |
||
39 | * @param Serializer $serializer |
||
40 | * @param LoggerInterface $logger |
||
41 | */ |
||
42 | public function __construct(Client $client, Serializer $serializer, LoggerInterface $logger) |
||
48 | |||
49 | /** |
||
50 | * Push event to queue. |
||
51 | * |
||
52 | * @param EventInterface $event |
||
53 | * |
||
54 | * @return bool |
||
55 | */ |
||
56 | public function push(EventInterface $event) |
||
62 | |||
63 | /** |
||
64 | * Pop event from queue. Return NULL if queue is empty. |
||
65 | * |
||
66 | * @return EventInterface|null |
||
67 | */ |
||
68 | public function pop() |
||
89 | } |
||
90 |
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.