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 | abstract class BaseDoctrineJobManager extends ArchivableJobManager |
||
12 | { |
||
13 | /** Number of jobs to prune / reset / gather at a time */ |
||
14 | const FETCH_COUNT_MIN = 100; |
||
15 | const FETCH_COUNT_MAX = 500; |
||
16 | const SAVE_COUNT_MIN = 10; |
||
17 | const SAVE_COUNT_MAX = 100; |
||
18 | |||
19 | /** |
||
20 | * @var ObjectManager |
||
21 | */ |
||
22 | protected $objectManager; |
||
23 | |||
24 | /** |
||
25 | * DoctrineJobManager constructor. |
||
26 | * |
||
27 | 20 | * @param RunManager $runManager |
|
28 | * @param JobTimingManager $jobTimingManager |
||
29 | * @param ObjectManager $objectManager |
||
30 | * @param $jobClass |
||
31 | * @param $jobArchiveClass |
||
32 | */ |
||
33 | public function __construct( |
||
43 | 57 | ||
44 | View Code Duplication | protected function getFetchCount($totalCount) |
|
56 | 15 | ||
57 | 15 | View Code Duplication | protected function getSaveCount($totalCount) |
69 | |||
70 | /** |
||
71 | * @return ObjectManager |
||
72 | */ |
||
73 | public function getObjectManager() |
||
77 | |||
78 | /** |
||
79 | * @return ObjectRepository |
||
80 | */ |
||
81 | public function getRepository() |
||
85 | |||
86 | protected function flush() |
||
90 | |||
91 | public function deleteJob(\Dtc\QueueBundle\Model\Job $job) |
||
97 | } |
||
98 |
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.