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 GoalManager extends ManagerBase |
||
9 | { |
||
10 | /** |
||
11 | * Get a list of Goals. |
||
12 | * |
||
13 | * Example of how to structure the $options parameter: |
||
14 | * <code> |
||
15 | * $options = [ |
||
16 | * 'limit_by_site' => 'my-site-id' |
||
17 | * ]; |
||
18 | * </code> |
||
19 | * |
||
20 | * @see http://docs.decision-api.acquia.com/#goals_get |
||
21 | * |
||
22 | * @param array $options |
||
23 | * |
||
24 | * @throws \GuzzleHttp\Exception\RequestException |
||
25 | * |
||
26 | * @return \Acquia\LiftClient\Entity\Goal[] |
||
27 | */ |
||
28 | public function query($options = []) |
||
45 | |||
46 | /** |
||
47 | * Get a specific goal. |
||
48 | * |
||
49 | * @see http://docs.decision-api.acquia.com/#goals__goal_id__get |
||
50 | * |
||
51 | * @param array $id |
||
52 | * |
||
53 | * @throws \GuzzleHttp\Exception\RequestException |
||
54 | * |
||
55 | * @return \Acquia\LiftClient\Entity\Goal |
||
56 | */ |
||
57 | View Code Duplication | public function get($id) { |
|
66 | |||
67 | /** |
||
68 | * Add a goal. |
||
69 | * |
||
70 | * @see http://docs.decision-api.acquia.com/#goals_post |
||
71 | * |
||
72 | * @param \Acquia\LiftClient\Entity\Goal $goal |
||
73 | * |
||
74 | * @throws \GuzzleHttp\Exception\RequestException |
||
75 | * |
||
76 | * @return \Acquia\LiftClient\Entity\Goal |
||
77 | */ |
||
78 | View Code Duplication | public function add(Goal $goal) { |
|
86 | |||
87 | /** |
||
88 | * Deletes a goal by ID. |
||
89 | * |
||
90 | * @see http://docs.decision-api.acquia.com/#goals__goal_id__delete |
||
91 | * |
||
92 | * @param string $id |
||
93 | * |
||
94 | * @throws \GuzzleHttp\Exception\RequestException |
||
95 | * |
||
96 | * @return bool |
||
97 | */ |
||
98 | public function delete($id) { |
||
104 | } |
||
105 |
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.