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