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 | * Get a list of Goals. |
||
23 | * |
||
24 | * Example of how to structure the $options parameter: |
||
25 | * <code> |
||
26 | * $options = [ |
||
27 | * 'limit_by_site' => 'my-site-id' |
||
28 | * ]; |
||
29 | * </code> |
||
30 | * |
||
31 | * @see http://docs.decision-api.acquia.com/#goals_get |
||
32 | * |
||
33 | * @param array $options |
||
34 | * |
||
35 | * @throws \GuzzleHttp\Exception\RequestException |
||
36 | * |
||
37 | 10 | * @return \Acquia\LiftClient\Entity\Goal[] |
|
38 | */ |
||
39 | 6 | View Code Duplication | public function query($options = []) |
56 | |||
57 | /** |
||
58 | * Get a specific goal. |
||
59 | * |
||
60 | * @see http://docs.decision-api.acquia.com/#goals__goal_id__get |
||
61 | * |
||
62 | * @param array $id |
||
63 | * |
||
64 | * @throws \GuzzleHttp\Exception\RequestException |
||
65 | * |
||
66 | 6 | * @return \Acquia\LiftClient\Entity\Goal |
|
67 | */ |
||
68 | 6 | public function get($id) |
|
78 | |||
79 | /** |
||
80 | * Add a goal. |
||
81 | * |
||
82 | * @see http://docs.decision-api.acquia.com/#goals_post |
||
83 | * |
||
84 | * @param \Acquia\LiftClient\Entity\Goal $goal |
||
85 | * |
||
86 | * @throws \GuzzleHttp\Exception\RequestException |
||
87 | * |
||
88 | 9 | * @return \Acquia\LiftClient\Entity\GoalAddResponse |
|
89 | */ |
||
90 | public function add(Goal $goal) |
||
102 | |||
103 | /** |
||
104 | * Deletes a goal by ID. |
||
105 | * |
||
106 | * @see http://docs.decision-api.acquia.com/#goals__goal_id__delete |
||
107 | * |
||
108 | * @param string $id |
||
109 | * |
||
110 | * @throws \GuzzleHttp\Exception\RequestException |
||
111 | * |
||
112 | 6 | * @return bool |
|
113 | */ |
||
114 | 6 | public function delete($id) |
|
121 | |||
122 | /** |
||
123 | * Get query string of using the options. |
||
124 | * |
||
125 | * @param $options The options |
||
126 | * |
||
127 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
128 | * |
||
129 | * @return string The query string |
||
130 | */ |
||
131 | protected function getQueryString($options) { |
||
138 | } |
||
139 |