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 |
||
18 | class PredisCommandQueue implements CommandQueue |
||
19 | { |
||
20 | const LIST_KEY = 'commands'; |
||
21 | const FORMAT = 'predis'; |
||
22 | |||
23 | /** |
||
24 | * @var Client |
||
25 | */ |
||
26 | private $client; |
||
27 | |||
28 | /** |
||
29 | * @var Serializer |
||
30 | */ |
||
31 | private $serializer; |
||
32 | |||
33 | /** |
||
34 | * @var LoggerInterface |
||
35 | */ |
||
36 | private $logger; |
||
37 | |||
38 | /** |
||
39 | * @param Client $client |
||
40 | * @param Serializer $serializer |
||
41 | * @param LoggerInterface $logger |
||
42 | */ |
||
43 | public function __construct(Client $client, Serializer $serializer, LoggerInterface $logger) |
||
49 | |||
50 | /** |
||
51 | * Push command to queue. |
||
52 | * |
||
53 | * @param Command $command |
||
54 | * |
||
55 | * @return bool |
||
56 | */ |
||
57 | public function push(Command $command) |
||
63 | |||
64 | /** |
||
65 | * Pop command from queue. Return NULL if queue is empty. |
||
66 | * |
||
67 | * @return Command|null |
||
68 | */ |
||
69 | View Code Duplication | public function pop() |
|
90 | } |
||
91 |
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.