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