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 |
||
41 | class NodeController extends BaseController |
||
42 | { |
||
43 | public function __construct() |
||
47 | |||
48 | /** |
||
49 | * List All Nodes. |
||
50 | * |
||
51 | * Lists all nodes currently on the system. |
||
52 | * |
||
53 | * @Get("/nodes/{?page}") |
||
54 | * @Versions({"v1"}) |
||
55 | * @Parameters({ |
||
56 | * @Parameter("page", type="integer", description="The page of results to view.", default=1) |
||
57 | * }) |
||
58 | * @Response(200) |
||
59 | */ |
||
60 | public function lists(Request $request) |
||
64 | |||
65 | /** |
||
66 | * Create a New Node. |
||
67 | * |
||
68 | * @Post("/nodes") |
||
69 | * @Versions({"v1"}) |
||
70 | * @Transaction({ |
||
71 | * @Request({ |
||
72 | * 'name' => 'My API Node', |
||
73 | * 'location' => 1, |
||
74 | * 'public' => 1, |
||
75 | * 'fqdn' => 'daemon.wuzzle.woo', |
||
76 | * 'scheme' => 'https', |
||
77 | * 'memory' => 10240, |
||
78 | * 'memory_overallocate' => 100, |
||
79 | * 'disk' => 204800, |
||
80 | * 'disk_overallocate' => -1, |
||
81 | * 'daemonBase' => '/srv/daemon-data', |
||
82 | * 'daemonSFTP' => 2022, |
||
83 | * 'daemonListen' => 8080 |
||
84 | * }, headers={"Authorization": "Bearer <jwt-token>"}), |
||
85 | * @Response(200), |
||
86 | * @Response(422, body={ |
||
87 | * "message": "A validation error occured.", |
||
88 | * "errors": {}, |
||
89 | * "status_code": 422 |
||
90 | * }), |
||
91 | * @Response(503, body={ |
||
92 | * "message": "There was an error while attempting to add this node to the system.", |
||
93 | * "status_code": 503 |
||
94 | * }) |
||
95 | * }) |
||
96 | */ |
||
97 | public function create(Request $request) |
||
118 | |||
119 | /** |
||
120 | * List Specific Node. |
||
121 | * |
||
122 | * Lists specific fields about a server or all fields pertaining to that node. |
||
123 | * |
||
124 | * @Get("/nodes/{id}/{?fields}") |
||
125 | * @Versions({"v1"}) |
||
126 | * @Parameters({ |
||
127 | * @Parameter("id", type="integer", required=true, description="The ID of the node to get information on."), |
||
128 | * @Parameter("fields", type="string", required=false, description="A comma delimidated list of fields to include.") |
||
129 | * }) |
||
130 | * @Response(200) |
||
131 | */ |
||
132 | public function view(Request $request, $id, $fields = null) |
||
154 | |||
155 | public function config(Request $request, $id) |
||
164 | |||
165 | /** |
||
166 | * List all Node Allocations. |
||
167 | * |
||
168 | * Returns a listing of all allocations for every node. |
||
169 | * |
||
170 | * @Get("/nodes/allocations") |
||
171 | * @Versions({"v1"}) |
||
172 | * @Response(200) |
||
173 | */ |
||
174 | public function allocations(Request $request) |
||
178 | |||
179 | /** |
||
180 | * List Node Allocation based on assigned to ID. |
||
181 | * |
||
182 | * Returns a listing of the allocation for the specified server id. |
||
183 | * |
||
184 | * @Get("/nodes/allocations/{id}") |
||
185 | * @Versions({"v1"}) |
||
186 | * @Response(200) |
||
187 | */ |
||
188 | public function allocationsView(Request $request, $id) |
||
192 | |||
193 | /** |
||
194 | * Delete Node. |
||
195 | * |
||
196 | * @Delete("/nodes/{id}") |
||
197 | * @Versions({"v1"}) |
||
198 | * @Parameters({ |
||
199 | * @Parameter("id", type="integer", required=true, description="The ID of the node."), |
||
200 | * }) |
||
201 | * @Response(204) |
||
202 | */ |
||
203 | View Code Duplication | public function delete(Request $request, $id) |
|
216 | } |
||
217 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.