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 | 19 | public function save(TaskExecutionInterface $execution) |
|
| 44 | |||
| 45 | /** |
||
| 46 | * {@inheritdoc} |
||
| 47 | */ |
||
| 48 | 1 | public function remove(TaskExecutionInterface $execution) |
|
| 49 | { |
||
| 50 | 1 | $this->_em->remove($execution); |
|
| 51 | 1 | $this->_em->flush($execution); |
|
| 52 | |||
| 53 | 1 | return $this; |
|
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * {@inheritdoc} |
||
| 58 | */ |
||
| 59 | 8 | View Code Duplication | public function findAll($page = 1, $pageSize = null) |
| 72 | |||
| 73 | /** |
||
| 74 | * {@inheritdoc} |
||
| 75 | */ |
||
| 76 | 8 | public function findPending(TaskInterface $task) |
|
| 91 | |||
| 92 | /** |
||
| 93 | * {@inheritdoc} |
||
| 94 | */ |
||
| 95 | 5 | public function findByUuid($uuid) |
|
| 96 | { |
||
| 97 | try { |
||
| 98 | 5 | return $this->createQueryBuilder('e') |
|
| 99 | 5 | ->where('e.uuid = :uuid') |
|
| 100 | 5 | ->setParameter('uuid', $uuid) |
|
| 101 | 5 | ->getQuery() |
|
| 102 | 5 | ->getSingleResult(); |
|
| 103 | 1 | } catch (NoResultException $e) { |
|
| 104 | 1 | return; |
|
| 105 | } |
||
| 106 | } |
||
| 107 | |||
| 108 | /** |
||
| 109 | * {@inheritdoc} |
||
| 110 | */ |
||
| 111 | 4 | public function findByTask(TaskInterface $task) |
|
| 115 | |||
| 116 | /** |
||
| 117 | * {@inheritdoc} |
||
| 118 | */ |
||
| 119 | 5 | public function findByTaskUuid($taskUuid) |
|
| 128 | |||
| 129 | /** |
||
| 130 | * {@inheritdoc} |
||
| 131 | */ |
||
| 132 | 4 | public function findNextScheduled(\DateTime $dateTime = null) |
|
| 149 | } |
||
| 150 |