| Conditions | 8 |
| Paths | 11 |
| Total Lines | 54 |
| Code Lines | 35 |
| 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 |
||
| 63 | public function handle(ServerRequestInterface $request): ResponseInterface |
||
| 64 | { |
||
| 65 | $tree = Validator::attributes($request)->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 Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
||
| 73 | } |
||
| 74 | |||
| 75 | $adapter_id = Validator::attributes($request)->integer('adapter_id', -1); |
||
| 76 | $map_adapter = $this->mapadapter_data_service->find($adapter_id); |
||
| 77 | |||
| 78 | $map = $this->map_definition_service->find(Validator::parsedBody($request)->string('map_adapter_map', '')); |
||
| 79 | $mapping_property = Validator::parsedBody($request)->string('map_adapter_property_selected', ''); |
||
| 80 | |||
| 81 | $mapper = null; |
||
|
|
|||
| 82 | try { |
||
| 83 | $mapper = app(Validator::parsedBody($request)->string('map_adapter_mapper', '')); |
||
| 84 | } catch (BindingResolutionException $ex) { |
||
| 85 | } |
||
| 86 | |||
| 87 | if ($map_adapter === null || $map === null || $mapper === null || !($mapper instanceof PlaceMapperInterface)) { |
||
| 88 | FlashMessages::addMessage( |
||
| 89 | I18N::translate('The parameters for the map configuration are not valid.'), |
||
| 90 | 'danger' |
||
| 91 | ); |
||
| 92 | return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
||
| 93 | } |
||
| 94 | |||
| 95 | $mapper->setConfig($mapper->config()->withConfigUpdate($request)); |
||
| 96 | $new_map_adapter = $map_adapter->with($map, $mapper, $mapping_property); |
||
| 97 | try { |
||
| 98 | $this->mapadapter_data_service->update($new_map_adapter); |
||
| 99 | FlashMessages::addMessage( |
||
| 100 | I18N::translate('The map configuration has been successfully updated.'), |
||
| 101 | 'success' |
||
| 102 | ); |
||
| 103 | //phpcs:ignore Generic.Files.LineLength.TooLong |
||
| 104 | Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter “' . $map_adapter->id() . '” has been updated.'); |
||
| 105 | } catch (Throwable $ex) { |
||
| 106 | FlashMessages::addMessage( |
||
| 107 | I18N::translate('An error occured while updating the map configuration.'), |
||
| 108 | 'danger' |
||
| 109 | ); |
||
| 110 | //phpcs:ignore Generic.Files.LineLength.TooLong |
||
| 111 | Log::addErrorLog('Module ' . $this->module->title() . ' : Error when updating Map Adapter “' . $map_adapter->id() . '”: ' . $ex->getMessage()); |
||
| 112 | } |
||
| 113 | |||
| 114 | return Registry::responseFactory()->redirect(MapAdapterEditPage::class, [ |
||
| 115 | 'tree' => $tree->name(), |
||
| 116 | 'adapter_id' => $map_adapter->id() |
||
| 117 | ]); |
||
| 120 |