| Conditions | 9 |
| Paths | 11 |
| Total Lines | 62 |
| 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 |
||
| 56 | public function handle(ServerRequestInterface $request): ResponseInterface |
||
| 57 | { |
||
| 58 | $tree = Validator::attributes($request)->tree(); |
||
| 59 | |||
| 60 | if ($this->module === null) { |
||
| 61 | FlashMessages::addMessage( |
||
| 62 | I18N::translate('The attached module could not be found.'), |
||
| 63 | 'danger' |
||
| 64 | ); |
||
| 65 | return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
||
| 66 | } |
||
| 67 | |||
| 68 | |||
| 69 | $view_id = Validator::attributes($request)->integer('view_id', -1); |
||
| 70 | $view = $this->geoview_data_service->find($tree, $view_id, true); |
||
| 71 | |||
| 72 | $description = Validator::parsedBody($request)->string('view_description', ''); |
||
| 73 | $place_depth = Validator::parsedBody($request)->integer('view_depth', 1); |
||
| 74 | $top_places = Validator::parsedBody($request)->integer('view_top_places', 0); |
||
| 75 | |||
| 76 | $analysis = null; |
||
|
|
|||
| 77 | try { |
||
| 78 | $analysis = app(Validator::parsedBody($request)->string('view_analysis', '')); |
||
| 79 | } catch (BindingResolutionException $ex) { |
||
| 80 | } |
||
| 81 | |||
| 82 | if ( |
||
| 83 | $view === null |
||
| 84 | || $analysis === null || !($analysis instanceof GeoAnalysisInterface) |
||
| 85 | || $place_depth <= 0 && $top_places < 0 |
||
| 86 | ) { |
||
| 87 | FlashMessages::addMessage( |
||
| 88 | I18N::translate('The parameters for view with ID “%s” are not valid.', I18N::number($view_id)), |
||
| 89 | 'danger' |
||
| 90 | ); |
||
| 91 | return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
||
| 92 | } |
||
| 93 | |||
| 94 | $new_view = $view |
||
| 95 | ->with($view->isEnabled(), $description, $analysis, $place_depth, $top_places) |
||
| 96 | ->withGlobalSettingsUpdate($request); |
||
| 97 | |||
| 98 | try { |
||
| 99 | $this->geoview_data_service->update($new_view); |
||
| 100 | FlashMessages::addMessage( |
||
| 101 | I18N::translate('The geographical dispersion analysis view has been successfully updated.'), |
||
| 102 | 'success' |
||
| 103 | ); |
||
| 104 | //phpcs:ignore Generic.Files.LineLength.TooLong |
||
| 105 | Log::addConfigurationLog('Module ' . $this->module->title() . ' : View “' . $view->id() . '” has been updated.'); |
||
| 106 | } catch (Throwable $ex) { |
||
| 107 | FlashMessages::addMessage( |
||
| 108 | I18N::translate('An error occured while updating the geographical dispersion analysis view.'), |
||
| 109 | 'danger' |
||
| 110 | ); |
||
| 111 | //phpcs:ignore Generic.Files.LineLength.TooLong |
||
| 112 | Log::addErrorLog('Module ' . $this->module->title() . ' : Error when updating view “' . $view->id() . '”: ' . $ex->getMessage()); |
||
| 113 | } |
||
| 114 | |||
| 115 | return Registry::responseFactory()->redirect(GeoAnalysisViewEditPage::class, [ |
||
| 116 | 'tree' => $tree->name(), |
||
| 117 | 'view_id' => $view->id() |
||
| 118 | ]); |
||
| 121 |