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 | abstract class UserValidation |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * Validate and sanitize a username. |
||
| 15 | * |
||
| 16 | * @param string $name |
||
| 17 | * @return string |
||
| 18 | * @throws \Exception |
||
| 19 | */ |
||
| 20 | View Code Duplication | protected static function validateName($name) |
|
| 28 | |||
| 29 | /** |
||
| 30 | * Validate and sanitize a email address. |
||
| 31 | * |
||
| 32 | * @param string $emailValue |
||
| 33 | * @return string |
||
| 34 | * @throws \Exception |
||
| 35 | */ |
||
| 36 | protected static function validateEmail($emailValue) |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Validate and sanitize input data when create new user. |
||
| 48 | * |
||
| 49 | * @param array $input |
||
| 50 | * @return string |
||
| 51 | * @throws \Exception |
||
| 52 | */ |
||
| 53 | public static function validateInputOnCreateUser($input) |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Validate and sanitize input data when update a user. |
||
| 69 | * |
||
| 70 | * @param array $input |
||
| 71 | * @param object $user |
||
| 72 | * @return string |
||
| 73 | * @throws \Exception |
||
| 74 | */ |
||
| 75 | public static function validateInputOnUpdateUser($input, $user) |
||
| 91 | } |
||
| 92 |