Conditions | 5 |
Paths | 5 |
Total Lines | 58 |
Code Lines | 38 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
59 | public function handle(ServerRequestInterface $request): ResponseInterface |
||
60 | { |
||
61 | $this->layout = 'layouts/administration'; |
||
62 | |||
63 | $place_id = (int) $request->getAttribute('place_id'); |
||
64 | $location = $this->map_data_service->findById($place_id); |
||
65 | |||
66 | if ($location->id() === null) { |
||
67 | return redirect(route(MapDataList::class)); |
||
68 | } |
||
69 | |||
70 | $title = e($location->locationName()) . ' — ' . I18N::translate('Edit'); |
||
71 | |||
72 | // Build the breadcrumbs in reverse order |
||
73 | $breadcrumbs = [I18N::translate('Edit')]; |
||
74 | |||
75 | $tmp = $location; |
||
76 | while ($tmp->id() !== null) { |
||
77 | $breadcrumbs[route(MapDataList::class, ['parent_id' => $tmp->id()])] = e($tmp->locationName()); |
||
78 | |||
79 | $tmp = $tmp->parent(); |
||
80 | } |
||
81 | |||
82 | $breadcrumbs[route(ControlPanel::class)] = I18N::translate('Control panel'); |
||
83 | $breadcrumbs[route(MapDataList::class)] = I18N::translate('Geographic data'); |
||
84 | |||
85 | $latitude = $location->latitude(); |
||
86 | $longitude = $location->longitude(); |
||
87 | $map_bounds = $location->boundingRectangle(); |
||
88 | |||
89 | // If the current co-ordinates are unknown, leave the input fields empty, |
||
90 | // and show a marker in the middle of the map. |
||
91 | if ($latitude === null || $longitude === null) { |
||
92 | $latitude = ''; |
||
93 | $longitude = ''; |
||
94 | |||
95 | $marker_position = [ |
||
96 | ($map_bounds[0][0] + $map_bounds[1][0]) / 2.0, |
||
97 | ($map_bounds[0][1] + $map_bounds[1][1]) / 2.0, |
||
98 | ]; |
||
99 | } else { |
||
100 | $marker_position = [$latitude, $longitude]; |
||
101 | } |
||
102 | |||
103 | return $this->viewResponse('admin/location-edit', [ |
||
104 | 'breadcrumbs' => $breadcrumbs, |
||
105 | 'title' => $title, |
||
106 | 'location' => $location, |
||
107 | 'latitude' => $latitude, |
||
108 | 'longitude' => $longitude, |
||
109 | 'map_bounds' => $map_bounds, |
||
110 | 'marker_position' => $marker_position, |
||
111 | 'parent' => $location->parent(), |
||
112 | 'provider' => [ |
||
113 | 'url' => 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', |
||
114 | 'options' => [ |
||
115 | 'attribution' => '<a href="https://www.openstreetmap.org/copyright">© OpenStreetMap</a> contributors', |
||
116 | 'max_zoom' => 19 |
||
117 | ] |
||
122 |