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