Conditions | 8 |
Paths | 7 |
Total Lines | 60 |
Code Lines | 38 |
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 handle(ServerRequestInterface $request): ResponseInterface |
||
70 | { |
||
71 | $tree = Validator::attributes($request)->tree(); |
||
72 | |||
73 | if ($this->module === null) { |
||
74 | FlashMessages::addMessage( |
||
75 | I18N::translate('The attached module could not be found.'), |
||
76 | 'danger' |
||
77 | ); |
||
78 | return redirect(route(AdminConfigPage::class, ['tree' => $tree->name()])); |
||
79 | } |
||
80 | |||
81 | $view_id = Validator::attributes($request)->integer('view_id', -1); |
||
82 | $view = $this->geoview_data_service->find($tree, $view_id); |
||
83 | |||
84 | $map = $this->map_definition_service->find(Validator::parsedBody($request)->string('map_adapter_map', '')); |
||
85 | $mapping_property = Validator::parsedBody($request)->string('map_adapter_property_selected', ''); |
||
86 | |||
87 | $mapper = null; |
||
|
|||
88 | try { |
||
89 | $mapper = app(Validator::parsedBody($request)->string('map_adapter_mapper', '')); |
||
90 | } catch (BindingResolutionException $ex) { |
||
91 | } |
||
92 | |||
93 | if ($view === null || $map === null || $mapper === null || !($mapper instanceof PlaceMapperInterface)) { |
||
94 | FlashMessages::addMessage( |
||
95 | I18N::translate('The parameters for the map configuration are not valid.'), |
||
96 | 'danger' |
||
97 | ); |
||
98 | return redirect(route(AdminConfigPage::class, ['tree' => $tree->name()])); |
||
99 | } |
||
100 | |||
101 | $new_adapter_id = $this->mapadapter_data_service->insertGetId( |
||
102 | new GeoAnalysisMapAdapter( |
||
103 | 0, |
||
104 | $view_id, |
||
105 | $map, |
||
106 | $mapper, |
||
107 | new MapViewConfig($mapping_property, $mapper->config()->withConfigUpdate($request)) |
||
108 | ) |
||
109 | ); |
||
110 | if ($new_adapter_id > 0) { |
||
111 | FlashMessages::addMessage( |
||
112 | I18N::translate('The map configuration has been successfully added.'), |
||
113 | 'success' |
||
114 | ); |
||
115 | //phpcs:ignore Generic.Files.LineLength.TooLong |
||
116 | Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter “' . $new_adapter_id . '” has been added.'); |
||
117 | } else { |
||
118 | FlashMessages::addMessage( |
||
119 | I18N::translate('An error occured while adding a new map configuration.'), |
||
120 | 'danger' |
||
121 | ); |
||
122 | //phpcs:ignore Generic.Files.LineLength.TooLong |
||
123 | Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter could not be added. See error log.'); |
||
124 | } |
||
125 | |||
126 | return redirect(route(GeoAnalysisViewEditPage::class, [ |
||
127 | 'tree' => $tree->name(), |
||
128 | 'view_id' => $view_id |
||
129 | ])); |
||
132 |