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 |
||
11 | class GoalManager extends ManagerBase |
||
12 | { |
||
13 | /** |
||
14 | * {@inheritdoc} |
||
15 | */ |
||
16 | protected $queryParameters = [ |
||
17 | 'global' => null, |
||
18 | 'limit_by_site' => null, |
||
19 | ]; |
||
20 | |||
21 | /** |
||
22 | * @var array Valid boolean query strings. |
||
23 | */ |
||
24 | private $validBooleanQueryStrings = [ |
||
25 | 'true', |
||
26 | 'false', |
||
27 | ]; |
||
28 | |||
29 | /** |
||
30 | * Get a list of Goals. |
||
31 | * |
||
32 | * Example of how to structure the $options parameter: |
||
33 | * <code> |
||
34 | * $options = [ |
||
35 | * 'global' => 'false', |
||
36 | * 'limit_by_site' => 'true', |
||
37 | * ]; |
||
38 | * </code> |
||
39 | * Note: the options "global" and "limit_by_site" work together to determine |
||
40 | * what goals are coming back. Please see the truth table on following page. |
||
41 | * |
||
42 | * @see http://docs.decision-api.acquia.com/#goals_get |
||
43 | * |
||
44 | * @param array $options |
||
45 | * |
||
46 | * @throws \GuzzleHttp\Exception\RequestException |
||
47 | * |
||
48 | * @return \Acquia\LiftClient\Entity\Goal[] |
||
49 | */ |
||
50 | 18 | View Code Duplication | public function query($options = []) |
67 | |||
68 | /** |
||
69 | * Get a specific goal. |
||
70 | * |
||
71 | * @see http://docs.decision-api.acquia.com/#goals__goal_id__get |
||
72 | * |
||
73 | * @param array $id |
||
74 | * |
||
75 | * @throws \GuzzleHttp\Exception\RequestException |
||
76 | * |
||
77 | * @return \Acquia\LiftClient\Entity\Goal |
||
78 | */ |
||
79 | 6 | public function get($id) |
|
89 | |||
90 | /** |
||
91 | * Add a goal. |
||
92 | * |
||
93 | * @see http://docs.decision-api.acquia.com/#goals_post |
||
94 | * |
||
95 | * @param \Acquia\LiftClient\Entity\Goal $goal |
||
96 | * |
||
97 | * @throws \GuzzleHttp\Exception\RequestException |
||
98 | * |
||
99 | * @return \Acquia\LiftClient\Entity\GoalAddResponse |
||
100 | */ |
||
101 | 9 | public function add(Goal $goal) |
|
114 | |||
115 | /** |
||
116 | * Deletes a goal by ID. |
||
117 | * |
||
118 | * @see http://docs.decision-api.acquia.com/#goals__goal_id__delete |
||
119 | * |
||
120 | * @param string $id |
||
121 | * |
||
122 | * @throws \GuzzleHttp\Exception\RequestException |
||
123 | * |
||
124 | * @return bool |
||
125 | */ |
||
126 | 6 | public function delete($id) |
|
133 | |||
134 | /** |
||
135 | * Get query string of using the options. |
||
136 | * |
||
137 | * @param $options The options |
||
138 | * |
||
139 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
140 | * |
||
141 | * @return string The query string |
||
142 | */ |
||
143 | 12 | protected function getQueryString($options) { |
|
153 | } |
||
154 |
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.