Conditions | 6 |
Paths | 10 |
Total Lines | 53 |
Code Lines | 31 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 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 |
||
76 | public function handle(ServerRequestInterface $request): ResponseInterface |
||
77 | { |
||
78 | $parent_id = $request->getAttribute('parent_id'); |
||
79 | |||
80 | if ($parent_id === null) { |
||
81 | $parent = new PlaceLocation(''); |
||
82 | } else { |
||
83 | $parent_id = (int) $parent_id; |
||
84 | $parent = $this->map_data_service->findById($parent_id); |
||
85 | } |
||
86 | |||
87 | // Request for a non-existent location? |
||
88 | if ($parent_id !== null && $parent->id() === null) { |
||
89 | return redirect(route(__CLASS__)); |
||
90 | } |
||
91 | |||
92 | // Automatically import any new/missing places. |
||
93 | $this->map_data_service->importMissingLocations(); |
||
94 | |||
95 | $breadcrumbs = []; |
||
96 | |||
97 | if ($parent->id() !== null) { |
||
98 | $breadcrumbs[] = e($parent->locationName()); |
||
99 | } |
||
100 | |||
101 | $tmp = $parent->parent(); |
||
102 | |||
103 | while ($tmp->id() !== null) { |
||
104 | $breadcrumbs[route(__CLASS__, ['parent_id' => $tmp->id()])] = $tmp->locationName(); |
||
105 | |||
106 | $tmp = $tmp->parent(); |
||
107 | } |
||
108 | |||
109 | $title = I18N::translate('Geographic data'); |
||
110 | |||
111 | $breadcrumbs[route(__CLASS__)] = $title; |
||
112 | |||
113 | $breadcrumbs[route(ControlPanel::class)] = I18N::translate('Control panel'); |
||
114 | |||
115 | $list_module = $this->module_service |
||
116 | ->findByInterface(PlaceHierarchyListModule::class) |
||
117 | ->first(); |
||
118 | |||
119 | $this->layout = 'layouts/administration'; |
||
120 | |||
121 | return $this->viewResponse('admin/locations', [ |
||
122 | 'active' => $this->map_data_service->activePlaces($parent), |
||
123 | 'all_trees' => $this->tree_service->all(), |
||
124 | 'breadcrumbs' => array_reverse($breadcrumbs), |
||
125 | 'parent_id' => $parent_id, |
||
126 | 'placelist' => $this->map_data_service->getPlaceListLocation($parent_id), |
||
127 | 'list_module' => $list_module, |
||
128 | 'title' => $title, |
||
129 | ]); |
||
132 |