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 |
||
21 | class TaskRepository extends EntityRepository implements TaskRepositoryInterface |
||
22 | { |
||
23 | /** |
||
24 | * {@inheritdoc} |
||
25 | */ |
||
26 | 9 | public function create($handlerClass, $workload = null) |
|
30 | |||
31 | /** |
||
32 | * {@inheritdoc} |
||
33 | */ |
||
34 | public function findByUuid($uuid) |
||
38 | |||
39 | /** |
||
40 | * {@inheritdoc} |
||
41 | */ |
||
42 | 9 | public function persist(TaskInterface $task) |
|
48 | |||
49 | /** |
||
50 | * {@inheritdoc} |
||
51 | */ |
||
52 | public function remove(TaskInterface $task) |
||
58 | |||
59 | /** |
||
60 | * {@inheritdoc} |
||
61 | */ |
||
62 | 9 | public function flush() |
|
68 | |||
69 | /** |
||
70 | * {@inheritdoc} |
||
71 | */ |
||
72 | 5 | View Code Duplication | public function findAll($page = 1, $pageSize = null) |
84 | |||
85 | /** |
||
86 | * {@inheritdoc} |
||
87 | */ |
||
88 | 2 | public function findEndBeforeNow() |
|
92 | |||
93 | /** |
||
94 | * Returns task where last-execution is before given date-time. |
||
95 | * |
||
96 | * @param \DateTime $dateTime |
||
97 | * |
||
98 | * @return TaskInterface[] |
||
99 | */ |
||
100 | 2 | public function findEndBefore(\DateTime $dateTime) |
|
108 | } |
||
109 |
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.