| Conditions | 10 |
| Paths | 11 |
| Total Lines | 39 |
| Code Lines | 24 |
| 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 | $this->layout = 'layouts/ajax'; |
||
| 61 | |||
| 62 | if ($this->module === null) { |
||
| 63 | throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
||
| 64 | } |
||
| 65 | $tree = $request->getAttribute('tree'); |
||
| 66 | assert($tree instanceof Tree); |
||
| 67 | |||
| 68 | $adapter_id = (int) $request->getAttribute('adapter_id'); |
||
| 69 | $map_adapter = $this->mapadapter_data_service->find($adapter_id); |
||
| 70 | |||
| 71 | $mapper_class = $request->getQueryParams()['mapper'] ?? ''; |
||
| 72 | $mapper = null; |
||
| 73 | if ($mapper_class === '' && $map_adapter !== null) { |
||
| 74 | $mapper = $map_adapter->placeMapper(); |
||
| 75 | } else { |
||
| 76 | try { |
||
| 77 | $mapper = app($mapper_class); |
||
| 78 | } catch (BindingResolutionException $ex) { |
||
|
|
|||
| 79 | } |
||
| 80 | |||
| 81 | if ( |
||
| 82 | $mapper !== null && $map_adapter !== null && |
||
| 83 | get_class($map_adapter->placeMapper()) === get_class($mapper) |
||
| 84 | ) { |
||
| 85 | $mapper = $map_adapter->placeMapper(); |
||
| 86 | } |
||
| 87 | } |
||
| 88 | |||
| 89 | if ($mapper === null || !($mapper instanceof PlaceMapperInterface)) { |
||
| 90 | throw new HttpNotFoundException( |
||
| 91 | I18N::translate('The configuration for the place mapper could not be found.') |
||
| 92 | ); |
||
| 93 | } |
||
| 94 | |||
| 95 | return $this->viewResponse('layouts/ajax', [ |
||
| 96 | 'content' => $mapper->config()->configContent($this->module, $tree) |
||
| 97 | ]); |
||
| 100 |