Complex classes like AbstractRestResourceController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use AbstractRestResourceController, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
30 | abstract class AbstractRestResourceController implements RestResourceControllerInterface |
||
31 | { |
||
32 | /** |
||
33 | * {@inheritdoc} |
||
34 | */ |
||
35 | 10 | public function listAction(Request $request) |
|
60 | |||
61 | /** |
||
62 | * {@inheritdoc} |
||
63 | */ |
||
64 | 14 | public function postAction(Request $request) |
|
82 | |||
83 | /** |
||
84 | * {@inheritdoc} |
||
85 | */ |
||
86 | 32 | public function getAction(Request $request, $id) |
|
95 | |||
96 | /** |
||
97 | * {@inheritdoc} |
||
98 | */ |
||
99 | 12 | public function putAction(Request $request, $id) |
|
117 | |||
118 | /** |
||
119 | * {@inheritdoc} |
||
120 | */ |
||
121 | 4 | public function deleteAction(Request $request, $id) |
|
129 | |||
130 | /** |
||
131 | * {@inheritdoc} |
||
132 | */ |
||
133 | 6 | public function listSubresourceAction(Request $request, $id, string $subresource) |
|
159 | |||
160 | /** |
||
161 | * {@inheritdoc} |
||
162 | */ |
||
163 | 4 | public function postSubresourceAction(Request $request, $id, string $subresource) |
|
186 | |||
187 | /** |
||
188 | * {@inheritdoc} |
||
189 | */ |
||
190 | 12 | public function putSubresourceAction(Request $request, $id, string $subresource, $subId) |
|
198 | |||
199 | /** |
||
200 | * {@inheritdoc} |
||
201 | */ |
||
202 | 12 | public function deleteSubresourceAction(Request $request, $id, string $subresource, $subId = null) |
|
210 | |||
211 | /** |
||
212 | * @param object $entity |
||
213 | * |
||
214 | * @return object |
||
215 | */ |
||
216 | 12 | protected function postProcessPostedEntity($entity) |
|
220 | |||
221 | /** |
||
222 | * @param object $entity |
||
223 | * |
||
224 | * @return object |
||
225 | */ |
||
226 | 10 | protected function postProcessPuttedEntity($entity) |
|
230 | |||
231 | /** |
||
232 | * @param object $parent |
||
233 | * @param string $subresource |
||
234 | * @param object $entity |
||
235 | * |
||
236 | * @return object |
||
237 | */ |
||
238 | 2 | protected function postProcessSubResourcePostedEntity($parent, $subresource, $entity) |
|
242 | |||
243 | /** |
||
244 | * @param int|string $id |
||
245 | * |
||
246 | * @return object |
||
247 | */ |
||
248 | 56 | protected function fetchEntity($id) |
|
257 | |||
258 | /** |
||
259 | * @param int $page |
||
260 | * @param int $perPage |
||
261 | * |
||
262 | * @return Paginator|array |
||
263 | */ |
||
264 | 6 | protected function listEntities(int $page = 1, int $perPage = 50) |
|
268 | |||
269 | /** |
||
270 | * @param object $entity |
||
271 | * |
||
272 | * @return object |
||
273 | */ |
||
274 | 10 | protected function createEntity($entity) |
|
278 | |||
279 | /** |
||
280 | * @param object $entity |
||
281 | * |
||
282 | * @return object |
||
283 | */ |
||
284 | 10 | protected function updateEntity($entity) |
|
288 | |||
289 | /** |
||
290 | * @param object $parent |
||
291 | * @param string $subresource |
||
292 | * |
||
293 | * @return object |
||
294 | */ |
||
295 | 2 | protected function createAssociation($parent, string $subresource) |
|
299 | |||
300 | /** |
||
301 | * @param object $entity |
||
302 | * @param string $property |
||
303 | * @param int $page |
||
304 | * @param int $perPage |
||
305 | * |
||
306 | * @return Paginator|array |
||
307 | */ |
||
308 | 6 | protected function listSubresource($entity, string $property, int $page = 1, int $perPage = 50) |
|
312 | |||
313 | 80 | protected function getEntityClass() |
|
317 | |||
318 | 2 | protected function getSubResourceEntityClass($subresource) |
|
325 | |||
326 | 72 | protected function getServiceId() |
|
330 | |||
331 | 80 | protected function getCurrentRequest() |
|
335 | |||
336 | 70 | protected function assertMethodGranted(string $methodName, $entity = null) |
|
343 | |||
344 | /** |
||
345 | * @param string $methodName |
||
346 | * @param object $entity |
||
347 | * @param string $subresource |
||
348 | */ |
||
349 | 30 | protected function assertSubResourceMethodGranted($methodName, $entity, string $subresource): void |
|
359 | |||
360 | /** |
||
361 | * @return ClassMetadata |
||
362 | */ |
||
363 | 80 | protected function getClassMetadata() |
|
371 | |||
372 | protected function resolveSubject($entity, $propertyPath) |
||
381 | |||
382 | /** |
||
383 | * @param Right $right |
||
384 | * @param object $entity |
||
385 | */ |
||
386 | 46 | protected function assertRightGranted(Right $right, $entity = null) |
|
396 | |||
397 | /** |
||
398 | * @param object $parent |
||
399 | * @param string $subresource |
||
400 | * @param object $entity |
||
401 | * |
||
402 | * @return object |
||
403 | */ |
||
404 | 2 | protected function createSubResource($parent, $subresource, $entity) |
|
408 | |||
409 | 62 | protected function parseIncludes(Request $request) |
|
425 | |||
426 | 46 | protected function denyAccessUnlessGranted($attributes, $object = null, $message = 'Access Denied.') |
|
432 | |||
433 | 2 | protected function parseConstraintViolations(ConstraintViolationListInterface $errors) |
|
447 | |||
448 | 12 | protected function addPaginationHeaders(Response $response, int $page, int $perPage, int $total) |
|
459 | |||
460 | /** |
||
461 | * @return CrudServiceInterface |
||
462 | */ |
||
463 | abstract protected function getService(); |
||
464 | |||
465 | /** |
||
466 | * @return Normalizer |
||
467 | */ |
||
468 | abstract protected function getNormalizer(); |
||
469 | |||
470 | /** |
||
471 | * @return ValidatorInterface |
||
472 | */ |
||
473 | abstract protected function getValidator(); |
||
474 | |||
475 | /** |
||
476 | * @return RestRequestParser |
||
477 | */ |
||
478 | abstract protected function getRequestParser(); |
||
479 | |||
480 | /** |
||
481 | * @return RequestStack |
||
482 | */ |
||
483 | abstract protected function getRequestStack(); |
||
484 | |||
485 | /** |
||
486 | * @return MetadataFactoryInterface |
||
487 | */ |
||
488 | abstract protected function getMetadataFactory(); |
||
489 | |||
490 | /** |
||
491 | * @return PropertyAccessorInterface |
||
492 | */ |
||
493 | abstract protected function getPropertyAccessor(); |
||
494 | |||
495 | /** |
||
496 | * @return AuthorizationCheckerInterface |
||
497 | */ |
||
498 | abstract protected function getAuthorizationChecker(); |
||
499 | |||
500 | /** |
||
501 | * @return EntityManagerInterface |
||
502 | */ |
||
503 | abstract protected function getEntityManager(); |
||
504 | } |
||
505 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.