Conditions | 9 |
Paths | 11 |
Total Lines | 56 |
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 |
||
58 | public function handle(ServerRequestInterface $request): ResponseInterface |
||
59 | { |
||
60 | $tree = Validator::attributes($request)->tree(); |
||
61 | |||
62 | if ($this->module === null) { |
||
63 | FlashMessages::addMessage( |
||
64 | I18N::translate('The attached module could not be found.'), |
||
65 | 'danger' |
||
66 | ); |
||
67 | return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
||
68 | } |
||
69 | |||
70 | $type = Validator::parsedBody($request)->isInArray(['table', 'map'])->string('view_type', ''); |
||
71 | $description = Validator::parsedBody($request)->string('view_description', ''); |
||
72 | $place_depth = Validator::parsedBody($request)->integer('view_depth', 1); |
||
73 | |||
74 | $analysis = null; |
||
|
|||
75 | try { |
||
76 | $analysis = app(Validator::parsedBody($request)->string('view_analysis', '')); |
||
77 | } catch (BindingResolutionException $ex) { |
||
78 | } |
||
79 | |||
80 | if ($type === '' || $place_depth <= 0 || $analysis === null || !($analysis instanceof GeoAnalysisInterface)) { |
||
81 | FlashMessages::addMessage( |
||
82 | I18N::translate('The parameters for the new view are not valid.'), |
||
83 | 'danger' |
||
84 | ); |
||
85 | return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
||
86 | } |
||
87 | |||
88 | if ($type === 'map') { |
||
89 | $new_view = new GeoAnalysisMap(0, $tree, true, $description, $analysis, $place_depth); |
||
90 | } else { |
||
91 | $new_view = new GeoAnalysisTable(0, $tree, true, $description, $analysis, $place_depth); |
||
92 | } |
||
93 | |||
94 | $new_view_id = $this->geoview_data_service->insertGetId($new_view); |
||
95 | if ($new_view_id > 0) { |
||
96 | FlashMessages::addMessage( |
||
97 | I18N::translate('The geographical dispersion analysis view has been successfully added.'), |
||
98 | 'success' |
||
99 | ); |
||
100 | //phpcs:ignore Generic.Files.LineLength.TooLong |
||
101 | Log::addConfigurationLog('Module ' . $this->module->title() . ' : View “' . $new_view_id . '” has been added.'); |
||
102 | return Registry::responseFactory()->redirect( |
||
103 | GeoAnalysisViewEditPage::class, |
||
104 | ['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 Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
||
114 | } |
||
117 |