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