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 |
||
| 11 | class DutyGroups extends DutyHelper |
||
| 12 | { |
||
| 13 | public function __construct(Duty $duty) |
||
| 17 | |||
| 18 | public function htmlOutput() |
||
| 19 | { |
||
| 20 | $newCollection = new Collection(); |
||
| 21 | |||
| 22 | foreach ($this->list as $entry) { |
||
| 23 | $row = $this->buildHTMLUserRow($entry); |
||
| 24 | |||
| 25 | $newCollection->push([ |
||
| 26 | 'row' => $row, |
||
| 27 | 'id' => $entry['id'], |
||
| 28 | 'date' => $entry['date'], |
||
| 29 | ]); |
||
| 30 | } |
||
| 31 | |||
| 32 | return $newCollection; |
||
| 33 | } |
||
| 34 | |||
| 35 | public function emailOutput() |
||
| 46 | |||
| 47 | View Code Duplication | public function recordNextEntry() |
|
| 56 | |||
| 57 | public function getLastWorked() |
||
| 63 | |||
| 64 | public function queryList() |
||
| 70 | |||
| 71 | public function combineListWithDates() |
||
| 89 | |||
| 90 | public function insertFromDutySwap() |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @param $entry |
||
| 113 | * |
||
| 114 | * @return string |
||
| 115 | */ |
||
| 116 | private function buildHTMLUserRow($entry) |
||
| 130 | } |
||
| 131 |