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 |
||
24 | class TaskExecutionRepository extends EntityRepository implements TaskExecutionRepositoryInterface |
||
|
|||
25 | { |
||
26 | /** |
||
27 | * {@inheritdoc} |
||
28 | */ |
||
29 | 9 | public function create(TaskInterface $task, \DateTime $scheduleTime) |
|
33 | |||
34 | /** |
||
35 | * {@inheritdoc} |
||
36 | */ |
||
37 | 9 | public function save(TaskExecutionInterface $execution) |
|
38 | { |
||
39 | 9 | $this->_em->persist($execution); |
|
40 | |||
41 | 9 | return $this; |
|
42 | } |
||
43 | |||
44 | /** |
||
45 | * {@inheritdoc} |
||
46 | */ |
||
47 | public function remove(TaskExecutionInterface $execution) |
||
48 | { |
||
49 | $this->_em->remove($execution); |
||
50 | |||
51 | return $this; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * {@inheritdoc} |
||
56 | */ |
||
57 | 6 | View Code Duplication | public function findAll($page = 1, $pageSize = null) |
70 | |||
71 | /** |
||
72 | * {@inheritdoc} |
||
73 | */ |
||
74 | 7 | public function findByStartTime(TaskInterface $task, \DateTime $scheduleTime) |
|
89 | |||
90 | /** |
||
91 | * {@inheritdoc} |
||
92 | */ |
||
93 | public function findByTask(TaskInterface $task) |
||
94 | { |
||
95 | return $this->createQueryBuilder('e') |
||
96 | ->innerJoin('e.task', 't') |
||
97 | ->where('t.uuid = :uuid') |
||
98 | ->setParameter('uuid', $task->getUuid()) |
||
99 | ->getQuery() |
||
100 | ->getResult(); |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * {@inheritdoc} |
||
105 | */ |
||
106 | 2 | public function findScheduled(\DateTime $dateTime = null) |
|
120 | } |
||
121 |