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 |
||
25 | class Routes extends HttpApi |
||
26 | { |
||
27 | /** |
||
28 | * Fetches the list of Routes. Note that Routes are defined globally, |
||
29 | * per account, not per domain as most of other API calls. |
||
30 | * |
||
31 | * @param int $limit Maximum number of records to return. (100 by default) |
||
32 | * @param int $skip Number of records to skip. (0 by default) |
||
33 | * |
||
34 | * @return IndexResponse |
||
35 | */ |
||
36 | View Code Duplication | public function index($limit = 100, $skip = 0) |
|
52 | |||
53 | /** |
||
54 | * Returns a single Route object based on its ID. |
||
55 | * |
||
56 | * @param string $routeId Route ID returned by the Routes::index() method |
||
57 | * |
||
58 | * @return RouteDto |
||
59 | */ |
||
60 | public function show($routeId) |
||
68 | |||
69 | /** |
||
70 | * Creates a new Route. |
||
71 | * |
||
72 | * @param string $expression A filter expression like "match_recipient('.*@gmail.com')" |
||
73 | * @param array $actions Route action. This action is executed when the expression evaluates to True. Example: "forward('[email protected]')" |
||
74 | * @param string $description An arbitrary string |
||
75 | * @param int $priority Integer: smaller number indicates higher priority. Higher priority routes are handled first. Defaults to 0. |
||
76 | * |
||
77 | * @return CreateResponse |
||
78 | */ |
||
79 | View Code Duplication | public function create($expression, array $actions, $description, $priority = 0) |
|
97 | |||
98 | /** |
||
99 | * Updates a given Route by ID. All parameters are optional. |
||
100 | * This API call only updates the specified fields leaving others unchanged. |
||
101 | * |
||
102 | * @param string $routeId Route ID returned by the Routes::index() method |
||
103 | * @param string|null $expression A filter expression like "match_recipient('.*@gmail.com')" |
||
104 | * @param array|null $actions Route action. This action is executed when the expression evaluates to True. Example: "forward('[email protected]')" |
||
105 | * @param string|null $description An arbitrary string |
||
106 | * @param int|null $priority Integer: smaller number indicates higher priority. Higher priority routes are handled first. Defaults to 0. |
||
107 | * |
||
108 | * @return UpdateResponse |
||
109 | */ |
||
110 | public function update($routeId, $expression = null, array $actions = null, $description = null, $priority = null) |
||
141 | |||
142 | /** |
||
143 | * Deletes a Route based on the ID. |
||
144 | * |
||
145 | * @param string $routeId Route ID returned by the Routes::index() method |
||
146 | * |
||
147 | * @return DeleteResponse |
||
148 | */ |
||
149 | View Code Duplication | public function delete($routeId) |
|
157 | } |
||
158 |
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.