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 save(TaskInterface $task) |
|
| 43 | { |
||
| 44 | 9 | $this->_em->persist($task); |
|
| 45 | |||
| 46 | 9 | return $this; |
|
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * {@inheritdoc} |
||
| 51 | */ |
||
| 52 | public function remove(TaskInterface $task) |
||
| 53 | { |
||
| 54 | $this->_em->remove($task); |
||
| 55 | |||
| 56 | return $this; |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * {@inheritdoc} |
||
| 61 | */ |
||
| 62 | 5 | View Code Duplication | public function findAll($page = 1, $pageSize = null) |
| 74 | |||
| 75 | /** |
||
| 76 | * {@inheritdoc} |
||
| 77 | */ |
||
| 78 | 2 | public function findEndBeforeNow() |
|
| 82 | |||
| 83 | /** |
||
| 84 | * Returns task where last-execution is before given date-time. |
||
| 85 | * |
||
| 86 | * @param \DateTime $dateTime |
||
| 87 | * |
||
| 88 | * @return TaskInterface[] |
||
| 89 | */ |
||
| 90 | 2 | public function findEndBefore(\DateTime $dateTime) |
|
| 98 | } |
||
| 99 |