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 | abstract class TaskValidation extends BaseValidation |
||
11 | { |
||
12 | /** |
||
13 | * Validate and sanitize input data when create new task. |
||
14 | * |
||
15 | * @param array|object|null $input |
||
16 | * @return array |
||
17 | * @throws \Exception |
||
18 | */ |
||
19 | public static function validateInputOnCreateTask($input) |
||
32 | |||
33 | /** |
||
34 | * Validate and sanitize input data when update a task. |
||
35 | * |
||
36 | * @param array|object|null $input |
||
37 | * @param object $task |
||
38 | * @return array |
||
39 | * @throws \Exception |
||
40 | */ |
||
41 | public static function validateInputOnUpdateTask($input, $task) |
||
57 | |||
58 | /** |
||
59 | * @param array $input |
||
60 | * @param object $task |
||
61 | * @return string |
||
62 | */ |
||
63 | public static function validateNameOnUpdateTask($input, $task) |
||
72 | |||
73 | /** |
||
74 | * @param array $input |
||
75 | * @param object $task |
||
76 | * @return int |
||
77 | */ |
||
78 | public static function validateStatusOnUpdateTask($input, $task) |
||
87 | } |
||
88 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.