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 ProgramRepository |
||
| 11 | { |
||
| 12 | |||
| 13 | /** |
||
| 14 | * @var VisitorModel |
||
| 15 | */ |
||
| 16 | protected $visitorModel; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @var ProgramModel |
||
| 20 | */ |
||
| 21 | protected $programModel; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @param VisitorModel $visitorModel |
||
| 25 | * @param ProgramModel $programModel |
||
| 26 | */ |
||
| 27 | public function __construct( |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @param int $meetingId |
||
| 37 | */ |
||
| 38 | public function setMeetingId(int $meetingId): self |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @return array |
||
| 48 | */ |
||
| 49 | public function all(): array |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @param int $id |
||
| 56 | * @return Nette\Database\Table\ActiveRow |
||
| 57 | */ |
||
| 58 | public function find(int $id): ActiveRow |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @param int $VisitorId |
||
| 65 | * @return array |
||
| 66 | */ |
||
| 67 | public function findByVisitorId(int $VisitorId): array |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @param int $programId |
||
| 74 | * @return array |
||
| 75 | */ |
||
| 76 | public function findTutor(int $programId): ActiveRow |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @param int $programId |
||
| 83 | * @return array |
||
| 84 | */ |
||
| 85 | public function findVisitors(int $programId): array |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @param Nette\Utils\ArrayHash $program |
||
| 92 | * @return boolean |
||
| 93 | */ |
||
| 94 | public function create(ArrayHash $program) |
||
| 100 | |||
| 101 | /** |
||
| 102 | * @param Nette\Utils\ArrayHash $program |
||
| 103 | * @return boolean |
||
| 104 | */ |
||
| 105 | public function update(int $id, ArrayHash $program) |
||
| 111 | |||
| 112 | /** |
||
| 113 | * @param int $id |
||
| 114 | * @return boolean |
||
| 115 | */ |
||
| 116 | public function delete(int $id) |
||
| 120 | |||
| 121 | /** |
||
| 122 | * @param int $visitorId |
||
| 123 | * @return array |
||
| 124 | */ |
||
| 125 | View Code Duplication | public function assembleFormPrograms(int $visitorId): array |
|
| 140 | |||
| 141 | /** |
||
| 142 | * @param Nette\Utils\ArrayHash $program |
||
| 143 | * @return Nette\Utils\ArrayHash |
||
| 144 | */ |
||
| 145 | protected function transformDisplayInRegValue(ArrayHash $program): ArrayHash |
||
| 155 | |||
| 156 | /** |
||
| 157 | * @return ProgramModel |
||
| 158 | */ |
||
| 159 | protected function getProgramModel() |
||
| 163 | |||
| 164 | /** |
||
| 165 | * @param ProgramModel $model |
||
| 166 | * @return $this |
||
| 167 | */ |
||
| 168 | protected function setProgramModel(ProgramModel $model): self |
||
| 174 | |||
| 175 | /** |
||
| 176 | * @return VisitorModel |
||
| 177 | */ |
||
| 178 | protected function getVisitorModel(): VisitorModel |
||
| 182 | |||
| 183 | /** |
||
| 184 | * @param VisitorModel $model |
||
| 185 | * @return VisitorService |
||
| 186 | */ |
||
| 187 | protected function setVisitorModel(VisitorModel $model): self |
||
| 193 | |||
| 194 | } |
||
| 195 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.