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 |
||
15 | class QueueScheduler |
||
16 | { |
||
17 | /** |
||
18 | * @var ManagerRegistry |
||
19 | */ |
||
20 | protected $doctrine; |
||
21 | |||
22 | /** |
||
23 | * @param ManagerRegistry $doctrine |
||
24 | */ |
||
25 | public function setDoctrine($doctrine) |
||
29 | |||
30 | /** |
||
31 | * @var TaskManager |
||
32 | */ |
||
33 | private $taskManager; |
||
34 | |||
35 | /** |
||
36 | * @param TaskManager $taskManager |
||
37 | */ |
||
38 | public function setTaskManager(TaskManager $taskManager) |
||
42 | |||
43 | /** |
||
44 | * |
||
45 | */ |
||
46 | public function schedule() |
||
57 | |||
58 | /** |
||
59 | * @param ScheduleInterface $schedule |
||
60 | */ |
||
61 | private function queue(ScheduleInterface $schedule) |
||
73 | |||
74 | /** |
||
75 | * @param ScheduleInterface $schedule |
||
76 | * @return \DateTime|null |
||
77 | */ |
||
78 | View Code Duplication | private function checkNextRunDate(ScheduleInterface $schedule) |
|
96 | |||
97 | /** |
||
98 | * @param ScheduleInterface $schedule |
||
99 | * @return \DateTime|null |
||
100 | */ |
||
101 | View Code Duplication | private function checkPreviousRunDate(ScheduleInterface $schedule) |
|
120 | } |
||
121 |
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.