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 SlotManager extends ManagerBase |
||
9 | { |
||
10 | /** |
||
11 | * Get a list of slots. |
||
12 | * |
||
13 | * Example of how to structure the $options parameter: |
||
14 | * <code> |
||
15 | * $options = [ |
||
16 | * 'visible_on_page' => 'http://localhost/blog/*', |
||
17 | * 'status' => 'enabled', |
||
18 | * ]; |
||
19 | * </code> |
||
20 | * |
||
21 | * @see http://docs.decision-api.acquia.com/#slots_get |
||
22 | * |
||
23 | * @param array $options |
||
24 | * |
||
25 | * @throws \GuzzleHttp\Exception\RequestException |
||
26 | * |
||
27 | * @return \Acquia\LiftClient\Entity\Slot[] |
||
28 | */ |
||
29 | public function query($options = []) |
||
52 | |||
53 | /** |
||
54 | * Get a specific slot. |
||
55 | * |
||
56 | * Example of how to structure the $options parameter: |
||
57 | * |
||
58 | * @see http://docs.decision-api.acquia.com/#slots__slotId__get |
||
59 | * |
||
60 | * @param array $id |
||
61 | * |
||
62 | * @throws \GuzzleHttp\Exception\RequestException |
||
63 | * |
||
64 | * @return \Acquia\LiftClient\Entity\Slot |
||
65 | */ |
||
66 | View Code Duplication | public function get($id) { |
|
75 | |||
76 | /** |
||
77 | * Add a slot. |
||
78 | * |
||
79 | * @param \Acquia\LiftClient\Entity\Slot $slot |
||
80 | * |
||
81 | * @throws \GuzzleHttp\Exception\RequestException |
||
82 | * |
||
83 | * @return \Acquia\LiftClient\Entity\Slot |
||
84 | */ |
||
85 | View Code Duplication | public function add(Slot $slot) { |
|
93 | |||
94 | /** |
||
95 | * Deletes a slot by ID. |
||
96 | * |
||
97 | * @param string $id |
||
98 | * |
||
99 | * @throws \GuzzleHttp\Exception\RequestException |
||
100 | * |
||
101 | * @return bool |
||
102 | */ |
||
103 | public function delete($id) { |
||
109 | } |
||
110 |
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.