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 |
||
67 | public function __invoke(Request $request) |
||
68 | { |
||
69 | if (!$request->get('admin') || !$request->isXmlHttpRequest()) { |
||
70 | return $this->render($this->templateRegistry->getTemplate('search'), [ |
||
71 | 'base_template' => $request->isXmlHttpRequest() ? |
||
72 | $this->templateRegistry->getTemplate('ajax') : |
||
73 | $this->templateRegistry->getTemplate('layout'), |
||
74 | 'breadcrumbs_builder' => $this->breadcrumbsBuilder, |
||
75 | 'admin_pool' => $this->pool, |
||
76 | 'query' => $request->get('q'), |
||
77 | 'groups' => $this->pool->getDashboardGroups(), |
||
78 | ]); |
||
79 | } |
||
80 | |||
81 | try { |
||
82 | $admin = $this->pool->getAdminByAdminCode($request->get('admin')); |
||
83 | } catch (ServiceNotFoundException $e) { |
||
84 | throw new \RuntimeException('Unable to find the Admin instance', $e->getCode(), $e); |
||
85 | } |
||
86 | |||
87 | if (!$admin instanceof AdminInterface) { |
||
88 | throw new \RuntimeException('The requested service is not an Admin instance'); |
||
89 | } |
||
90 | |||
91 | $results = []; |
||
92 | |||
93 | $page = false; |
||
94 | $total = false; |
||
95 | if ($pager = $this->searchHandler->search( |
||
96 | $admin, |
||
97 | $request->get('q'), |
||
98 | $request->get('page'), |
||
99 | $request->get('offset') |
||
100 | )) { |
||
101 | foreach ($pager->getResults() as $result) { |
||
102 | $results[] = [ |
||
103 | 'label' => $admin->toString($result), |
||
104 | 'link' => $admin->generateObjectUrl('edit', $result), |
||
105 | 'id' => $admin->id($result), |
||
106 | ]; |
||
107 | } |
||
108 | $page = (int) $pager->getPage(); |
||
109 | $total = (int) $pager->getNbResults(); |
||
|
|||
110 | } |
||
111 | |||
112 | $response = new JsonResponse([ |
||
113 | 'results' => $results, |
||
114 | 'page' => $page, |
||
115 | 'total' => $total, |
||
116 | ]); |
||
117 | $response->setPrivate(); |
||
118 | |||
119 | return $response; |
||
120 | } |
||
121 | } |
||
122 |
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.