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 |
||
8 | class RoleRepository |
||
9 | { |
||
10 | /** |
||
11 | * Create a new user instance after a valid registration. |
||
12 | * |
||
13 | * @param array $data The data used to create the user. |
||
14 | * |
||
15 | * @return \Xetaravel\Models\User |
||
16 | */ |
||
17 | View Code Duplication | public static function create(array $data): User |
|
30 | |||
31 | /** |
||
32 | * Update the role informations after a valid update request. |
||
33 | * |
||
34 | * @param array $data The data used to update the user. |
||
35 | * @param \Xetaravel\Models\Role $role The role to update. |
||
36 | * |
||
37 | * @return bool |
||
38 | */ |
||
39 | public static function update(array $data, Role $role): bool |
||
48 | } |
||
49 |
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.