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 |
||
32 | class ContactController extends RestController implements ClassResourceInterface |
||
33 | { |
||
34 | /** |
||
35 | * REST GET list |
||
36 | * |
||
37 | * @QueryParam( |
||
38 | * name="page", requirements="\d+", nullable=true, description="Page number, starting from 1. Defaults to 1." |
||
39 | * ) |
||
40 | * @QueryParam( |
||
41 | * name="limit", requirements="\d+", nullable=true, description="Number of items per page. defaults to 10." |
||
42 | * ) |
||
43 | * @QueryParam( |
||
44 | * name="createdAt", |
||
45 | * requirements="\d{4}(-\d{2}(-\d{2}([T ]\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|([-+]\d{2}(:?\d{2})?))?)?)?)?", |
||
46 | * nullable=true, |
||
47 | * description="Date in RFC 3339 format. For example: 2009-11-05T13:15:30Z, 2008-07-01T22:35:17+08:00" |
||
48 | * ) |
||
49 | * @QueryParam( |
||
50 | * name="updatedAt", |
||
51 | * requirements="\d{4}(-\d{2}(-\d{2}([T ]\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|([-+]\d{2}(:?\d{2})?))?)?)?)?", |
||
52 | * nullable=true, |
||
53 | * description="Date in RFC 3339 format. For example: 2009-11-05T13:15:30Z, 2008-07-01T22:35:17+08:00" |
||
54 | * ) |
||
55 | * @QueryParam( |
||
56 | * name="ownerId", |
||
57 | * requirements="\d+", |
||
58 | * nullable=true, |
||
59 | * description="Id of owner user" |
||
60 | * ) |
||
61 | * @QueryParam( |
||
62 | * name="ownerUsername", |
||
63 | * requirements=".+", |
||
64 | * nullable=true, |
||
65 | * description="Username of owner user" |
||
66 | * ) |
||
67 | * @QueryParam( |
||
68 | * name="phone", |
||
69 | * requirements=".+", |
||
70 | * nullable=true, |
||
71 | * description="Phone number of contact" |
||
72 | * ) |
||
73 | * @QueryParam( |
||
74 | * name="assigneeId", |
||
75 | * requirements="\d+", |
||
76 | * nullable=true, |
||
77 | * description="Id of assignee" |
||
78 | * ) |
||
79 | * @QueryParam( |
||
80 | * name="assigneeUsername", |
||
81 | * requirements=".+", |
||
82 | * nullable=true, |
||
83 | * description="Username of assignee" |
||
84 | * ) |
||
85 | * @ApiDoc( |
||
86 | * description="Get all contacts items", |
||
87 | * resource=true |
||
88 | * ) |
||
89 | * @AclAncestor("oro_contact_view") |
||
90 | * |
||
91 | * @throws \Exception |
||
92 | * @return Response |
||
93 | */ |
||
94 | public function cgetAction() |
||
125 | |||
126 | /** |
||
127 | * REST GET item |
||
128 | * |
||
129 | * @param string $id |
||
130 | * |
||
131 | * @ApiDoc( |
||
132 | * description="Get contact item", |
||
133 | * resource=true |
||
134 | * ) |
||
135 | * @AclAncestor("oro_contact_view") |
||
136 | * @return Response |
||
137 | */ |
||
138 | public function getAction($id) |
||
142 | |||
143 | /** |
||
144 | * REST PUT |
||
145 | * |
||
146 | * @param int $id Contact item id |
||
147 | * |
||
148 | * @ApiDoc( |
||
149 | * description="Update contact", |
||
150 | * resource=true |
||
151 | * ) |
||
152 | * @AclAncestor("oro_contact_update") |
||
153 | * @return Response |
||
154 | */ |
||
155 | public function putAction($id) |
||
159 | |||
160 | /** |
||
161 | * Create new contact |
||
162 | * |
||
163 | * @ApiDoc( |
||
164 | * description="Create new contact", |
||
165 | * resource=true |
||
166 | * ) |
||
167 | * @AclAncestor("oro_contact_create") |
||
168 | */ |
||
169 | public function postAction() |
||
173 | |||
174 | /** |
||
175 | * REST DELETE |
||
176 | * |
||
177 | * @param int $id |
||
178 | * |
||
179 | * @ApiDoc( |
||
180 | * description="Delete Contact", |
||
181 | * resource=true |
||
182 | * ) |
||
183 | * @Acl( |
||
184 | * id="oro_contact_delete", |
||
185 | * type="entity", |
||
186 | * permission="DELETE", |
||
187 | * class="OroContactBundle:Contact" |
||
188 | * ) |
||
189 | * @return Response |
||
190 | */ |
||
191 | public function deleteAction($id) |
||
195 | |||
196 | /** |
||
197 | * Get entity Manager |
||
198 | * |
||
199 | * @return ApiEntityManager |
||
200 | */ |
||
201 | public function getManager() |
||
205 | |||
206 | /** |
||
207 | * @return FormInterface |
||
208 | */ |
||
209 | public function getForm() |
||
213 | |||
214 | /** |
||
215 | * @return ApiFormHandler |
||
216 | */ |
||
217 | public function getFormHandler() |
||
221 | |||
222 | /** |
||
223 | * @param Contact $entity |
||
224 | * |
||
225 | * @SuppressWarnings(PHPMD.NPathComplexity) |
||
226 | */ |
||
227 | protected function fixRequestAttributes($entity) |
||
270 | |||
271 | /** |
||
272 | * @return string |
||
273 | */ |
||
274 | protected function getFormAlias() |
||
278 | |||
279 | /** |
||
280 | * {@inheritDoc} |
||
281 | */ |
||
282 | protected function fixFormData(array &$data, $entity) |
||
295 | } |
||
296 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.