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 |
||
| 10 | class TaskRepository extends BaseRepository |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @param object $database |
||
| 14 | */ |
||
| 15 | public function __construct(\PDO $database = null) |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Check if the task exists. |
||
| 22 | * |
||
| 23 | * @param int $taskId |
||
| 24 | * @return array $task |
||
| 25 | * @throws \Exception |
||
| 26 | */ |
||
| 27 | public function checkTask($taskId) |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Get all tasks. |
||
| 43 | * |
||
| 44 | * @return array |
||
| 45 | */ |
||
| 46 | public function getTasks() |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Search tasks by name. |
||
| 57 | * |
||
| 58 | * @param string $tasksName |
||
| 59 | * @return array |
||
| 60 | * @throws \Exception |
||
| 61 | */ |
||
| 62 | View Code Duplication | public function searchTasks($tasksName) |
|
| 76 | |||
| 77 | /** |
||
| 78 | * Get Task Sql Query. |
||
| 79 | * |
||
| 80 | * @return string |
||
| 81 | */ |
||
| 82 | public function getTaskQuery() |
||
| 86 | |||
| 87 | public function getTasksQuery() |
||
| 91 | |||
| 92 | public function searchTasksQuery() |
||
| 96 | |||
| 97 | public function createTaskQuery() |
||
| 101 | |||
| 102 | public function updateTaskQuery() |
||
| 106 | |||
| 107 | public function deleteTaskQuery() |
||
| 111 | } |
||
| 112 |