| Conditions | 7 |
| Paths | 7 |
| Total Lines | 74 |
| Code Lines | 53 |
| 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 create(Request $request) |
||
| 42 | { |
||
| 43 | $this->setAdminPrefs(); |
||
| 44 | $meta_title = 'Content Add'; |
||
| 45 | |||
| 46 | // Set the current action. |
||
| 47 | $action = $request->input('action') ?? 'view'; |
||
| 48 | |||
| 49 | $content = [ |
||
| 50 | 'id' => '', |
||
| 51 | 'title' => '', |
||
| 52 | 'url' => '', |
||
| 53 | 'body' => '', |
||
| 54 | 'metadescription' => '', |
||
| 55 | 'metakeywords' => '', |
||
| 56 | 'contenttype' => '', |
||
| 57 | 'status' => '', |
||
| 58 | 'ordinal' => '', |
||
| 59 | 'created_at' => '', |
||
| 60 | 'role' => '', |
||
| 61 | ]; |
||
| 62 | |||
| 63 | switch ($action) { |
||
| 64 | case 'add': |
||
| 65 | $meta_title = 'Content Add'; |
||
| 66 | $content['status'] = Content::STATUS_ENABLED; |
||
| 67 | $content['contenttype'] = Content::TYPE_USEFUL; |
||
| 68 | break; |
||
| 69 | |||
| 70 | case 'submit': |
||
| 71 | // Validate and add or update content |
||
| 72 | if ($request->missing('id') || empty($request->input('id'))) { |
||
| 73 | $returnid = $this->addContent($request->all()); |
||
| 74 | } else { |
||
| 75 | $this->updateContent($request->all()); |
||
| 76 | $returnid = $request->input('id'); |
||
| 77 | } |
||
| 78 | |||
| 79 | return redirect('admin/content-add?id='.$returnid); |
||
| 80 | |||
| 81 | case 'view': |
||
| 82 | default: |
||
| 83 | if ($request->has('id')) { |
||
| 84 | $meta_title = 'Content Edit'; |
||
| 85 | $id = $request->input('id'); |
||
| 86 | $content = $this->getContentById($id); |
||
| 87 | } |
||
| 88 | break; |
||
| 89 | } |
||
| 90 | |||
| 91 | $contenttypelist = [ |
||
| 92 | Content::TYPE_USEFUL => 'Useful Link', |
||
| 93 | Content::TYPE_INDEX => 'Homepage' |
||
| 94 | ]; |
||
| 95 | |||
| 96 | $rolelist = [ |
||
| 97 | Content::ROLE_EVERYONE => 'Everyone', |
||
| 98 | Content::ROLE_LOGGED_IN => 'Logged in Users', |
||
| 99 | Content::ROLE_ADMIN => 'Admins' |
||
| 100 | ]; |
||
| 101 | |||
| 102 | $this->viewData = array_merge($this->viewData, [ |
||
| 103 | 'status_ids' => [Content::STATUS_ENABLED, Content::STATUS_DISABLED], |
||
| 104 | 'status_names' => ['Enabled', 'Disabled'], |
||
| 105 | 'yesno_ids' => [1, 0], |
||
| 106 | 'yesno_names' => ['Yes', 'No'], |
||
| 107 | 'contenttypelist' => $contenttypelist, |
||
| 108 | 'content' => $content, |
||
| 109 | 'rolelist' => $rolelist, |
||
| 110 | 'meta_title' => $meta_title, |
||
| 111 | 'title' => $meta_title, |
||
| 112 | ]); |
||
| 113 | |||
| 114 | return view('admin.content.add', $this->viewData); |
||
| 115 | } |
||
| 250 |