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