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 | /** |
||
12 | * Get a list of slots. |
||
13 | * |
||
14 | * Example of how to structure the $options parameter: |
||
15 | * <code> |
||
16 | * $options = [ |
||
17 | * 'visible_on_page' => 'http://localhost/blog/*', |
||
18 | * 'status' => 'enabled', |
||
19 | * ]; |
||
20 | * </code> |
||
21 | * |
||
22 | * @see http://docs.decision-api.acquia.com/#slots_get |
||
23 | * |
||
24 | * @param array $options |
||
25 | * |
||
26 | * @return \Acquia\LiftClient\Entity\Slot[] |
||
27 | * |
||
28 | * @throws \GuzzleHttp\Exception\RequestException |
||
29 | */ |
||
30 | 6 | public function query($options = []) |
|
53 | |||
54 | |||
55 | /** |
||
56 | * Get a specific slot |
||
57 | * |
||
58 | * Example of how to structure the $options parameter: |
||
59 | * |
||
60 | * @see http://docs.decision-api.acquia.com/#slots__slotId__get |
||
61 | * |
||
62 | * @param array $options |
||
|
|||
63 | * |
||
64 | * @return \Acquia\LiftClient\Entity\Slot |
||
65 | * |
||
66 | * @throws \GuzzleHttp\Exception\RequestException |
||
67 | */ |
||
68 | 6 | View Code Duplication | public function get( |
79 | |||
80 | /** |
||
81 | * Add a slot |
||
82 | * |
||
83 | * @param \Acquia\LiftClient\Entity\Slot $slot |
||
84 | * |
||
85 | * @return \Acquia\LiftClient\Entity\Slot |
||
86 | * |
||
87 | * @throws \GuzzleHttp\Exception\RequestException |
||
88 | */ |
||
89 | 6 | View Code Duplication | public function add( |
99 | |||
100 | /** |
||
101 | * Deletes a slot by ID. |
||
102 | * |
||
103 | * @param string $id |
||
104 | * |
||
105 | * @return bool |
||
106 | * returns TRUE if successful. |
||
107 | * |
||
108 | * @throws \GuzzleHttp\Exception\RequestException |
||
109 | */ |
||
110 | 6 | public function delete( |
|
118 | } |
||
119 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.