| Conditions | 8 |
| Paths | 5 |
| Total Lines | 54 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 69 | public function __invoke(Request $request) |
||
| 70 | { |
||
| 71 | if (!$request->get('admin') || !$request->isXmlHttpRequest()) { |
||
| 72 | return $this->render($this->templateRegistry->getTemplate('search'), [ |
||
| 73 | 'base_template' => $request->isXmlHttpRequest() ? |
||
| 74 | $this->templateRegistry->getTemplate('ajax') : |
||
| 75 | $this->templateRegistry->getTemplate('layout'), |
||
| 76 | 'breadcrumbs_builder' => $this->breadcrumbsBuilder, |
||
| 77 | 'admin_pool' => $this->pool, |
||
| 78 | 'query' => $request->get('q'), |
||
| 79 | 'groups' => $this->pool->getDashboardGroups(), |
||
| 80 | ]); |
||
| 81 | } |
||
| 82 | |||
| 83 | try { |
||
| 84 | $admin = $this->pool->getAdminByAdminCode($request->get('admin')); |
||
| 85 | } catch (ServiceNotFoundException $e) { |
||
| 86 | throw new \RuntimeException('Unable to find the Admin instance', $e->getCode(), $e); |
||
| 87 | } |
||
| 88 | |||
| 89 | if (!$admin instanceof AdminInterface) { |
||
| 90 | throw new \RuntimeException('The requested service is not an Admin instance'); |
||
| 91 | } |
||
| 92 | |||
| 93 | $results = []; |
||
| 94 | |||
| 95 | $page = false; |
||
| 96 | $total = false; |
||
| 97 | if ($pager = $this->searchHandler->search( |
||
| 98 | $admin, |
||
| 99 | $request->get('q'), |
||
| 100 | $request->get('page'), |
||
| 101 | $request->get('offset') |
||
| 102 | )) { |
||
| 103 | foreach ($pager->getResults() as $result) { |
||
| 104 | $results[] = [ |
||
| 105 | 'label' => $admin->toString($result), |
||
| 106 | 'link' => $admin->generateObjectUrl('edit', $result), |
||
| 107 | 'id' => $admin->id($result), |
||
| 108 | ]; |
||
| 109 | } |
||
| 110 | $page = (int) $pager->getPage(); |
||
| 111 | $total = (int) $pager->getNbResults(); |
||
|
|
|||
| 112 | } |
||
| 113 | |||
| 114 | $response = new JsonResponse([ |
||
| 115 | 'results' => $results, |
||
| 116 | 'page' => $page, |
||
| 117 | 'total' => $total, |
||
| 118 | ]); |
||
| 119 | $response->setPrivate(); |
||
| 120 | |||
| 121 | return $response; |
||
| 122 | } |
||
| 123 | } |
||
| 124 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.