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) |
|
44 | |||
45 | /** |
||
46 | * {@inheritdoc} |
||
47 | */ |
||
48 | public function remove(TaskExecutionInterface $execution) |
||
55 | |||
56 | /** |
||
57 | * {@inheritdoc} |
||
58 | */ |
||
59 | 6 | View Code Duplication | public function findAll($page = 1, $pageSize = null) |
72 | |||
73 | /** |
||
74 | * {@inheritdoc} |
||
75 | */ |
||
76 | 7 | public function findPending(TaskInterface $task) |
|
77 | { |
||
78 | try { |
||
79 | 7 | return $this->createQueryBuilder('e') |
|
80 | 7 | ->innerJoin('e.task', 't') |
|
81 | 7 | ->where('t.uuid = :uuid') |
|
82 | 7 | ->andWhere('e.status in (:status)') |
|
83 | 7 | ->setParameter('uuid', $task->getUuid()) |
|
84 | 7 | ->setParameter('status', [TaskStatus::PLANNED, TaskStatus::STARTED]) |
|
85 | 7 | ->getQuery() |
|
86 | 7 | ->getSingleResult(); |
|
87 | 7 | } catch (NoResultException $e) { |
|
88 | 7 | return; |
|
89 | } |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * {@inheritdoc} |
||
94 | */ |
||
95 | public function findByTask(TaskInterface $task) |
||
104 | |||
105 | /** |
||
106 | * {@inheritdoc} |
||
107 | */ |
||
108 | 2 | public function findScheduled(\DateTime $dateTime = null) |
|
122 | } |
||
123 |