Conditions | 9 |
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 |
||
57 | public function handle(ServerRequestInterface $request): ResponseInterface |
||
58 | { |
||
59 | $tree = Validator::attributes($request)->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 | $type = Validator::parsedBody($request)->isInArray(['table', 'map'])->string('view_type', ''); |
||
72 | $description = Validator::parsedBody($request)->string('view_description', ''); |
||
73 | $place_depth = Validator::parsedBody($request)->integer('view_depth', 1); |
||
74 | |||
75 | $analysis = null; |
||
|
|||
76 | try { |
||
77 | $analysis = app(Validator::parsedBody($request)->string('view_analysis', '')); |
||
78 | } catch (BindingResolutionException $ex) { |
||
79 | } |
||
80 | |||
81 | if ($type === '' || $place_depth <= 0 || $analysis === null || !($analysis instanceof GeoAnalysisInterface)) { |
||
82 | FlashMessages::addMessage( |
||
83 | I18N::translate('The parameters for the new view are not valid.'), |
||
84 | 'danger' |
||
85 | ); |
||
86 | return redirect($admin_config_route); |
||
87 | } |
||
88 | |||
89 | if ($type === 'map') { |
||
90 | $new_view = new GeoAnalysisMap(0, $tree, true, $description, $analysis, $place_depth); |
||
91 | } else { |
||
92 | $new_view = new GeoAnalysisTable(0, $tree, true, $description, $analysis, $place_depth); |
||
93 | } |
||
94 | |||
95 | $new_view_id = $this->geoview_data_service->insertGetId($new_view); |
||
96 | if ($new_view_id > 0) { |
||
97 | FlashMessages::addMessage( |
||
98 | I18N::translate('The geographical dispersion analysis view has been successfully added.'), |
||
99 | 'success' |
||
100 | ); |
||
101 | //phpcs:ignore Generic.Files.LineLength.TooLong |
||
102 | Log::addConfigurationLog('Module ' . $this->module->title() . ' : View “' . $new_view_id . '” has been added.'); |
||
103 | return redirect( |
||
104 | route(GeoAnalysisViewEditPage::class, ['tree' => $tree->name(), 'view_id' => $new_view_id ]) |
||
105 | ); |
||
106 | } else { |
||
107 | FlashMessages::addMessage( |
||
108 | I18N::translate('An error occured while adding the geographical dispersion analysis view.'), |
||
109 | 'danger' |
||
110 | ); |
||
111 | //phpcs:ignore Generic.Files.LineLength.TooLong |
||
112 | Log::addConfigurationLog('Module ' . $this->module->title() . ' : A new View could not be added. See error log.'); |
||
113 | return redirect($admin_config_route); |
||
114 | } |
||
117 |