| Conditions | 11 |
| Paths | 2 |
| Total Lines | 81 |
| Code Lines | 58 |
| 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 |
||
| 46 | public function edit(Request $request) |
||
| 47 | { |
||
| 48 | $this->setAdminPrefs(); |
||
| 49 | $regexes = new Regexes(['Settings' => null, 'Table_Name' => 'category_regexes']); |
||
| 50 | |||
| 51 | // Set the current action. |
||
| 52 | $action = $request->input('action') ?? 'view'; |
||
| 53 | |||
| 54 | $regex = [ |
||
| 55 | 'id' => '', |
||
| 56 | 'group_regex' => '', |
||
| 57 | 'regex' => '', |
||
| 58 | 'description' => '', |
||
| 59 | 'ordinal' => '', |
||
| 60 | 'categories_id' => '', |
||
| 61 | 'status' => 1, ]; |
||
| 62 | |||
| 63 | $this->smarty->assign('regex', $regex); |
||
| 64 | |||
| 65 | switch ($action) { |
||
| 66 | case 'submit': |
||
| 67 | if (empty($request->input('group_regex'))) { |
||
| 68 | $this->smarty->assign('error', 'Group regex must not be empty!'); |
||
| 69 | break; |
||
| 70 | } |
||
| 71 | |||
| 72 | if (empty($request->input('regex'))) { |
||
| 73 | $this->smarty->assign('error', 'Regex cannot be empty'); |
||
| 74 | break; |
||
| 75 | } |
||
| 76 | |||
| 77 | if (! is_numeric($request->input('ordinal')) || $request->input('ordinal') < 0) { |
||
| 78 | $this->smarty->assign('error', 'Ordinal must be a number, 0 or higher.'); |
||
| 79 | break; |
||
| 80 | } |
||
| 81 | |||
| 82 | if (empty($request->input('id'))) { |
||
| 83 | $regexes->addRegex($request->all()); |
||
| 84 | } else { |
||
| 85 | $regexes->updateRegex($request->all()); |
||
| 86 | } |
||
| 87 | |||
| 88 | return redirect('admin/category_regexes-list'); |
||
| 89 | break; |
||
| 90 | |||
| 91 | case 'view': |
||
| 92 | default: |
||
| 93 | if ($request->has('id')) { |
||
| 94 | $meta_title = $title = 'Category Regex Edit'; |
||
| 95 | $id = $request->input('id'); |
||
| 96 | $regex = $regexes->getRegexByID($id); |
||
| 97 | } else { |
||
| 98 | $meta_title = $title = 'Category Regex Add'; |
||
| 99 | } |
||
| 100 | $this->smarty->assign('regex', $regex); |
||
| 101 | break; |
||
| 102 | } |
||
| 103 | |||
| 104 | $this->smarty->assign('status_ids', [Category::STATUS_ACTIVE, Category::STATUS_INACTIVE]); |
||
| 105 | $this->smarty->assign('status_names', ['Yes', 'No']); |
||
| 106 | |||
| 107 | $categories_db = Category::query() |
||
| 108 | ->select(['c.id', 'c.title', 'cp.title as parent_title']) |
||
| 109 | ->from('categories as c') |
||
| 110 | ->join('root_categories as cp', 'c.root_categories_id', '=', 'cp.id') |
||
| 111 | ->whereNotNull('c.root_categories_id') |
||
| 112 | ->orderBy('c.id') |
||
| 113 | ->get(); |
||
| 114 | $categories = ['category_names', 'category_ids']; |
||
| 115 | if ($categories_db) { |
||
| 116 | foreach ($categories_db as $category_db) { |
||
| 117 | $categories['category_names'][] = $category_db->parent_title.' '.$category_db->title.': '.$category_db->id; |
||
| 118 | $categories['category_ids'][] = $category_db->id; |
||
| 119 | } |
||
| 120 | } |
||
| 121 | $this->smarty->assign('category_names', $categories['category_names']); |
||
| 122 | $this->smarty->assign('category_ids', $categories['category_ids']); |
||
| 123 | |||
| 124 | $content = $this->smarty->fetch('category_regexes-edit.tpl'); |
||
| 125 | $this->smarty->assign(compact('title', 'meta_title', 'content')); |
||
| 126 | $this->adminrender(); |
||
| 127 | } |
||
| 129 |
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.