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 |
||
24 | class ProfileGateway extends AbstractGateway |
||
25 | { |
||
26 | /** |
||
27 | * @author EB |
||
28 | * @param $application |
||
29 | * @param array $personal |
||
30 | * @param $token |
||
31 | * @return array |
||
32 | */ |
||
33 | View Code Duplication | public function createPersonal($application, array $personal, $token) |
|
44 | |||
45 | /** |
||
46 | * @author EA |
||
47 | * @param int $user |
||
48 | * @param array $personal |
||
49 | * @param $token |
||
50 | * @return array |
||
51 | */ |
||
52 | View Code Duplication | public function setPersonal($user, array $personal, $token) |
|
63 | |||
64 | /** |
||
65 | * @author EB |
||
66 | * @param int $user |
||
67 | * @param array $financial |
||
68 | * @param $token |
||
69 | * @return array |
||
70 | */ |
||
71 | public function setFinancial($user, array $financial, $token) |
||
82 | |||
83 | /** |
||
84 | * @author EA |
||
85 | * @param int $user |
||
86 | * @param array $employment |
||
87 | * @param $token |
||
88 | * @return array |
||
89 | */ |
||
90 | public function setEmployment($user, array $employment, $token) |
||
101 | |||
102 | /** |
||
103 | * @author EA |
||
104 | * @param $user |
||
105 | * @param array $address |
||
106 | * @param $token |
||
107 | * @return array |
||
108 | */ |
||
109 | public function setAddress($user, array $address, $token) |
||
120 | } |
||
121 |
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.