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 |
||
| 12 | abstract class BaseValidation |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * Validate and sanitize a username. |
||
| 16 | * |
||
| 17 | * @param string $name |
||
| 18 | * @return string |
||
| 19 | * @throws \Exception |
||
| 20 | */ |
||
| 21 | View Code Duplication | protected static function validateName($name) |
|
| 29 | |||
| 30 | /** |
||
| 31 | * Validate and sanitize a email address. |
||
| 32 | * |
||
| 33 | * @param string $emailValue |
||
| 34 | * @return string |
||
| 35 | * @throws \Exception |
||
| 36 | */ |
||
| 37 | protected static function validateEmail($emailValue) |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Validate and sanitize a task name. |
||
| 49 | * |
||
| 50 | * @param string $name |
||
| 51 | * @return string |
||
| 52 | * @throws \Exception |
||
| 53 | */ |
||
| 54 | View Code Duplication | protected static function validateTaskName($name) |
|
| 62 | |||
| 63 | /** |
||
| 64 | * Validate and sanitize a task status. |
||
| 65 | * |
||
| 66 | * @param int $status |
||
| 67 | * @return string |
||
| 68 | * @throws \Exception |
||
| 69 | */ |
||
| 70 | protected static function validateStatus($status) |
||
| 78 | } |
||
| 79 |