| Conditions | 7 |
| Paths | 7 |
| Total Lines | 74 |
| Code Lines | 51 |
| 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 |
||
| 35 | public function create(Request $request) |
||
| 36 | { |
||
| 37 | $this->setAdminPrefs(); |
||
| 38 | $contents = new Contents(); |
||
| 39 | $meta_title = 'Content Add'; |
||
| 40 | |||
| 41 | // Set the current action. |
||
| 42 | $action = $request->input('action') ?? 'view'; |
||
| 43 | |||
| 44 | $content = [ |
||
| 45 | 'id' => '', |
||
| 46 | 'title' => '', |
||
| 47 | 'url' => '', |
||
| 48 | 'body' => '', |
||
| 49 | 'metadescription' => '', |
||
| 50 | 'metakeywords' => '', |
||
| 51 | 'contenttype' => '', |
||
| 52 | 'showinmenu' => '', |
||
| 53 | 'status' => '', |
||
| 54 | 'ordinal' => '', |
||
| 55 | 'created_at' => '', |
||
| 56 | 'role' => '', |
||
| 57 | ]; |
||
| 58 | |||
| 59 | switch ($action) { |
||
| 60 | case 'add': |
||
| 61 | $meta_title = 'Content Add'; |
||
| 62 | $content['showinmenu'] = '1'; |
||
| 63 | $content['status'] = '1'; |
||
| 64 | $content['contenttype'] = '2'; |
||
| 65 | break; |
||
| 66 | |||
| 67 | case 'submit': |
||
| 68 | // Validate and add or update. |
||
| 69 | if ($request->missing('id') || empty($request->input('id'))) { |
||
| 70 | $returnid = $contents->add($request->all()); |
||
| 71 | } else { |
||
| 72 | $content = $contents->update($request->all()); |
||
| 73 | $returnid = $content['id']; |
||
| 74 | } |
||
| 75 | |||
| 76 | return redirect('admin/content-add?id='.$returnid); |
||
| 77 | break; |
||
| 78 | |||
| 79 | case 'view': |
||
| 80 | default: |
||
| 81 | if ($request->has('id')) { |
||
| 82 | $meta_title = 'Content Edit'; |
||
| 83 | $id = $request->input('id'); |
||
| 84 | |||
| 85 | $content = $contents->getByID($id, User::ROLE_ADMIN); |
||
| 86 | } |
||
| 87 | break; |
||
| 88 | } |
||
| 89 | |||
| 90 | $this->smarty->assign('status_ids', [1, 0]); |
||
| 91 | $this->smarty->assign('status_names', ['Enabled', 'Disabled']); |
||
| 92 | |||
| 93 | $this->smarty->assign('yesno_ids', [1, 0]); |
||
| 94 | $this->smarty->assign('yesno_names', ['Yes', 'No']); |
||
| 95 | |||
| 96 | $contenttypelist = [1 => 'Useful Link', 2 => 'Article', 3 => 'Homepage']; |
||
| 97 | $this->smarty->assign('contenttypelist', $contenttypelist); |
||
| 98 | |||
| 99 | $this->smarty->assign('content', $content); |
||
| 100 | |||
| 101 | $rolelist = [1 => 'Everyone', 2 => 'Logged in Users', 3 => 'Admins']; |
||
| 102 | $this->smarty->assign('rolelist', $rolelist); |
||
| 103 | |||
| 104 | $content = $this->smarty->fetch('content-add.tpl'); |
||
| 105 | |||
| 106 | $this->smarty->assign(compact('meta_title', 'content')); |
||
| 107 | |||
| 108 | $this->adminrender(); |
||
| 109 | } |
||
| 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.