| Conditions | 10 |
| Paths | 4 |
| Total Lines | 59 |
| Code Lines | 39 |
| 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 |
||
| 41 | public function edit(Request $request) |
||
| 42 | { |
||
| 43 | $this->setAdminPrefs(); |
||
| 44 | $regexes = new Regexes(['Settings' => null, 'Table_Name' => 'collection_regexes']); |
||
| 45 | $error = ''; |
||
| 46 | $regex = ['id' => '', 'regex' => '', 'description' => '', 'group_regex' => '', 'ordinal' => '', 'status' => 1]; |
||
| 47 | |||
| 48 | switch ($request->input('action') ?? 'view') { |
||
| 49 | case 'submit': |
||
| 50 | if (empty($request->input('group_regex'))) { |
||
| 51 | $error = 'Group regex must not be empty!'; |
||
| 52 | break; |
||
| 53 | } |
||
| 54 | |||
| 55 | if (empty($request->input('regex'))) { |
||
| 56 | $error = 'Regex cannot be empty'; |
||
| 57 | break; |
||
| 58 | } |
||
| 59 | |||
| 60 | if (empty($request->input('description'))) { |
||
| 61 | $request->merge(['description' => '']); |
||
| 62 | } |
||
| 63 | |||
| 64 | if (! is_numeric($request->input('ordinal')) || $request->input('ordinal') < 0) { |
||
| 65 | $error = 'Ordinal must be a number, 0 or higher.'; |
||
| 66 | break; |
||
| 67 | } |
||
| 68 | |||
| 69 | if (empty($request->input('id'))) { |
||
| 70 | $regexes->addRegex($request->all()); |
||
| 71 | } else { |
||
| 72 | $regexes->updateRegex($request->all()); |
||
| 73 | } |
||
| 74 | |||
| 75 | return redirect('admin/collection_regexes-list'); |
||
| 76 | break; |
||
| 77 | |||
| 78 | case 'view': |
||
| 79 | default: |
||
| 80 | if ($request->has('id')) { |
||
| 81 | $meta_title = $title = 'Collections Regex Edit'; |
||
| 82 | $regex = $regexes->getRegexByID($request->input('id')); |
||
| 83 | } else { |
||
| 84 | $meta_title = $title = 'Collections Regex Add'; |
||
| 85 | $regex += ['status' => 1]; |
||
| 86 | } |
||
| 87 | break; |
||
| 88 | } |
||
| 89 | |||
| 90 | $this->smarty->assign('regex', $regex); |
||
| 91 | $this->smarty->assign('error', $error); |
||
| 92 | $this->smarty->assign('status_ids', [Category::STATUS_ACTIVE, Category::STATUS_INACTIVE]); |
||
| 93 | $this->smarty->assign('status_names', ['Yes', 'No']); |
||
| 94 | |||
| 95 | $content = $this->smarty->fetch('collection_regexes-edit.tpl'); |
||
| 96 | |||
| 97 | $this->smarty->assign(compact('title', 'meta_title', 'content')); |
||
| 98 | |||
| 99 | $this->adminrender(); |
||
| 100 | } |
||
| 128 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.