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 |
||
5 | trait EmployerManagers |
||
6 | { |
||
7 | use ResolvesCurrentUser; |
||
8 | |||
9 | /** |
||
10 | * Reference types and the rights of the Manager |
||
11 | * @param mixed $employerId |
||
12 | * @return array |
||
13 | */ |
||
14 | View Code Duplication | public function getManagerTypes($employerId = false) |
|
22 | |||
23 | |||
24 | /** |
||
25 | * Get employer managers |
||
26 | * |
||
27 | * @param mixed $employerId default resolved from profile |
||
28 | * @return array |
||
29 | */ |
||
30 | View Code Duplication | public function getManagers($employerId = false) |
|
38 | |||
39 | |||
40 | /** |
||
41 | * Get manager information |
||
42 | * |
||
43 | * @param string $managerId |
||
44 | * @param mixed $employerId default resolved from profile |
||
45 | * @return array |
||
46 | */ |
||
47 | View Code Duplication | public function getManager($managerId, $employerId = false) |
|
55 | |||
56 | /** |
||
57 | * @param mixed $employerId default resolved from profile |
||
58 | * @return array |
||
59 | */ |
||
60 | public function getManagersWhoHasVacancies($employerId = false) |
||
70 | |||
71 | protected function hasVacancies($manager) |
||
75 | |||
76 | protected function resolveEmployerId($employerId) |
||
83 | } |
||
84 |
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.