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 |
||
| 9 | trait ModelDeleting |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * Method fired before the Delete action is undertaken. |
||
| 13 | * |
||
| 14 | * @return |
||
| 15 | */ |
||
| 16 | protected function beforeDelete() |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Delete Action. |
||
| 22 | * |
||
| 23 | * Fires off beforeDelete(), doDelete() and afterDelete() |
||
| 24 | * |
||
| 25 | * @param int $modelitemId |
||
| 26 | * |
||
| 27 | * @return |
||
| 28 | */ |
||
| 29 | View Code Duplication | public function delete($modelitemId) |
|
| 43 | |||
| 44 | /** |
||
| 45 | * The actual delete action. |
||
| 46 | * |
||
| 47 | * @return |
||
| 48 | */ |
||
| 49 | private function doDelete() |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Method fired after the Delete action is complete. |
||
| 58 | * |
||
| 59 | * @return |
||
| 60 | */ |
||
| 61 | protected function afterDelete() |
||
| 64 | } |
||
| 65 |