| Conditions | 3 |
| Paths | 3 |
| Total Lines | 52 |
| Code Lines | 31 |
| 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 |
||
| 49 | public function handle(ServerRequestInterface $request): ResponseInterface |
||
| 50 | { |
||
| 51 | $tree = Validator::attributes($request)->tree(); |
||
| 52 | |||
| 53 | $admin_config_route = route(AdminConfigPage::class, ['tree' => $tree->name()]); |
||
| 54 | |||
| 55 | if ($this->module === null) { |
||
| 56 | FlashMessages::addMessage( |
||
| 57 | I18N::translate('The attached module could not be found.'), |
||
| 58 | 'danger' |
||
| 59 | ); |
||
| 60 | return redirect($admin_config_route); |
||
| 61 | } |
||
| 62 | |||
| 63 | $tree->setPreference( |
||
| 64 | 'MAJ_CERTIF_SHOW_CERT', |
||
| 65 | (string) Validator::parsedBody($request)->integer('MAJ_CERTIF_SHOW_CERT', Auth::PRIV_HIDE) |
||
| 66 | ); |
||
| 67 | $tree->setPreference( |
||
| 68 | 'MAJ_CERTIF_SHOW_NO_WATERMARK', |
||
| 69 | (string) Validator::parsedBody($request)->integer('MAJ_CERTIF_SHOW_NO_WATERMARK', Auth::PRIV_HIDE) |
||
| 70 | ); |
||
| 71 | $tree->setPreference( |
||
| 72 | 'MAJ_CERTIF_WM_DEFAULT', |
||
| 73 | Validator::parsedBody($request)->string('MAJ_CERTIF_WM_DEFAULT', '') |
||
| 74 | ); |
||
| 75 | |||
| 76 | $tree->setPreference( |
||
| 77 | 'MAJ_CERTIF_WM_FONT_MAXSIZE', |
||
| 78 | (string) ( |
||
| 79 | Validator::parsedBody($request)->isBetween(0, PHP_INT_MAX)->integer('MAJ_CERTIF_WM_FONT_MAXSIZE', 18) |
||
| 80 | ) |
||
| 81 | ); |
||
| 82 | |||
| 83 | // Only accept valid color for MAJ_WM_FONT_COLOR |
||
| 84 | $watermark_color = Validator::parsedBody($request)->string('MAJ_CERTIF_WM_FONT_COLOR', ''); |
||
| 85 | if (preg_match('/#([a-fA-F0-9]{3}){1,2}/', $watermark_color) === 1) { |
||
| 86 | $tree->setPreference('MAJ_CERTIF_WM_FONT_COLOR', $watermark_color); |
||
| 87 | } |
||
| 88 | |||
| 89 | // Only accept valid folders for MAJ_CERT_ROOTDIR |
||
| 90 | $cert_root_dir = Validator::parsedBody($request)->string('MAJ_CERTIF_ROOTDIR', ''); |
||
| 91 | $cert_root_dir = preg_replace('/[:\/\\\\]+/', '/', $cert_root_dir) ?? ''; |
||
| 92 | $cert_root_dir = trim($cert_root_dir, '/') . '/'; |
||
| 93 | $tree->setPreference('MAJ_CERTIF_ROOTDIR', $cert_root_dir); |
||
| 94 | |||
| 95 | FlashMessages::addMessage( |
||
| 96 | I18N::translate('The preferences for the module ā%sā have been updated.', $this->module->title()), |
||
| 97 | 'success' |
||
| 98 | ); |
||
| 99 | |||
| 100 | return redirect($admin_config_route); |
||
| 101 | } |
||
| 103 |