| Conditions | 8 |
| Paths | 11 |
| Total Lines | 57 |
| Code Lines | 37 |
| 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 |
||
| 62 | public function handle(ServerRequestInterface $request): ResponseInterface |
||
| 63 | { |
||
| 64 | $tree = $request->getAttribute('tree'); |
||
| 65 | assert($tree instanceof Tree); |
||
| 66 | |||
| 67 | if ($this->module === null) { |
||
| 68 | FlashMessages::addMessage( |
||
| 69 | I18N::translate('The attached module could not be found.'), |
||
| 70 | 'danger' |
||
| 71 | ); |
||
| 72 | return redirect(route(AdminConfigPage::class, ['tree' => $tree])); |
||
| 73 | } |
||
| 74 | |||
| 75 | $adapter_id = (int) $request->getAttribute('adapter_id'); |
||
| 76 | $map_adapter = $this->mapadapter_data_service->find($adapter_id); |
||
| 77 | |||
| 78 | $params = (array) $request->getParsedBody(); |
||
| 79 | |||
| 80 | $map = $this->map_definition_service->find($params['map_adapter_map'] ?? ''); |
||
| 81 | $mapping_property = $params['map_adapter_property_selected'] ?? ''; |
||
| 82 | |||
| 83 | $mapper = null; |
||
|
|
|||
| 84 | try { |
||
| 85 | $mapper = app($params['map_adapter_mapper'] ?? ''); |
||
| 86 | } catch (BindingResolutionException $ex) { |
||
| 87 | } |
||
| 88 | |||
| 89 | if ($map_adapter === null || $map === null || $mapper === null || !($mapper instanceof PlaceMapperInterface)) { |
||
| 90 | FlashMessages::addMessage( |
||
| 91 | I18N::translate('The parameters for the map configuration are not valid.'), |
||
| 92 | 'danger' |
||
| 93 | ); |
||
| 94 | return redirect(route(AdminConfigPage::class, ['tree' => $tree])); |
||
| 95 | } |
||
| 96 | |||
| 97 | $mapper->setConfig($mapper->config()->withConfigUpdate($request)); |
||
| 98 | $new_map_adapter = $map_adapter->with($map, $mapper, $mapping_property); |
||
| 99 | try { |
||
| 100 | $this->mapadapter_data_service->update($new_map_adapter); |
||
| 101 | FlashMessages::addMessage( |
||
| 102 | I18N::translate('The map configuration has been successfully updated.'), |
||
| 103 | 'success' |
||
| 104 | ); |
||
| 105 | //phpcs:ignore Generic.Files.LineLength.TooLong |
||
| 106 | Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter “' . $map_adapter->id() . '” has been updated.'); |
||
| 107 | } catch (Throwable $ex) { |
||
| 108 | FlashMessages::addMessage( |
||
| 109 | I18N::translate('An error occured while updating the map configuration.'), |
||
| 110 | 'danger' |
||
| 111 | ); |
||
| 112 | //phpcs:ignore Generic.Files.LineLength.TooLong |
||
| 113 | Log::addErrorLog('Module ' . $this->module->title() . ' : Error when updating Map Adapter “' . $map_adapter->id() . '”: ' . $ex->getMessage()); |
||
| 114 | } |
||
| 115 | |||
| 116 | return redirect(route(GeoAnalysisViewEditPage::class, [ |
||
| 117 | 'tree' => $tree->name(), |
||
| 118 | 'view_id' => $map_adapter->geoAnalysisViewId() |
||
| 119 | ])); |
||
| 122 |