| Conditions | 7 |
| Paths | 18 |
| Total Lines | 116 |
| Code Lines | 76 |
| 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 |
||
| 21 | public function edit(Request $request) |
||
| 22 | { |
||
| 23 | |||
| 24 | $meta_title = $title = 'Site Edit'; |
||
| 25 | $error = ''; |
||
| 26 | |||
| 27 | // set the current action |
||
| 28 | $action = $request->input('action') ?? 'view'; |
||
| 29 | |||
| 30 | switch ($action) { |
||
| 31 | case 'submit': |
||
| 32 | if ($request->missing('book_reqids')) { |
||
| 33 | $request->merge(['book_reqids' => []]); |
||
| 34 | } |
||
| 35 | Settings::settingsUpdate($request->all()); |
||
| 36 | |||
| 37 | return redirect()->to('admin/site-edit')->with('success', 'Settings updated successfully'); |
||
| 38 | |||
| 39 | case 'view': |
||
| 40 | default: |
||
| 41 | break; |
||
| 42 | } |
||
| 43 | |||
| 44 | // return a list of audiobooks, mags, ebooks, technical and foreign books |
||
| 45 | $result = Category::query()->whereIn('id', [Category::MUSIC_AUDIOBOOK, Category::BOOKS_MAGAZINES, Category::BOOKS_TECHNICAL, Category::BOOKS_FOREIGN])->get(['id', 'title']); |
||
| 46 | |||
| 47 | // setup the display lists for these categories |
||
| 48 | $book_reqids_ids = []; |
||
| 49 | $book_reqids_names = []; |
||
| 50 | foreach ($result as $bookcategory) { |
||
| 51 | $book_reqids_ids[] = $bookcategory['id']; |
||
| 52 | $book_reqids_names[] = $bookcategory['title']; |
||
| 53 | } |
||
| 54 | |||
| 55 | // convert from a string array to an int array as we want to use int |
||
| 56 | $book_reqids_ids = array_map(fn ($value) => (int) $value, $book_reqids_ids); |
||
| 57 | |||
| 58 | // convert from a list to an array as we need to use an array, but the Settings table only saves strings |
||
| 59 | $bookReqidsValue = Settings::settingValue('book_reqids') ?? ''; |
||
| 60 | $books_selected = $bookReqidsValue !== '' ? explode(',', $bookReqidsValue) : []; |
||
| 61 | |||
| 62 | // convert from a string array to an int array, filtering out empty values |
||
| 63 | $books_selected = array_map(fn ($value) => (int) trim($value), array_filter($books_selected)); |
||
| 64 | |||
| 65 | $compress_headers_warning = ! str_contains(config('settings.nntp_server'), 'astra') ? 'compress_headers_warning' : ''; |
||
| 66 | |||
| 67 | $this->viewData = array_merge($this->viewData, [ |
||
| 68 | 'error' => $error, |
||
| 69 | 'yesno' => [ |
||
| 70 | 'ids' => [1, 0], |
||
| 71 | 'names' => ['Yes', 'No'], |
||
| 72 | ], |
||
| 73 | 'passwd' => [ |
||
| 74 | 'ids' => [1, 0], |
||
| 75 | 'names' => ['Deep (requires unrar)', 'None'], |
||
| 76 | ], |
||
| 77 | 'langlist' => [ |
||
| 78 | 'ids' => [0, 2, 3, 1], |
||
| 79 | 'names' => ['English', 'Danish', 'French', 'German'], |
||
| 80 | ], |
||
| 81 | 'imdblang' => [ |
||
| 82 | 'ids' => ['en', 'da', 'nl', 'fi', 'fr', 'de', 'it', 'tlh', 'no', 'po', 'ru', 'es', 'sv'], |
||
| 83 | 'names' => ['English', 'Danish', 'Dutch', 'Finnish', 'French', 'German', 'Italian', 'Klingon', 'Norwegian', 'Polish', 'Russian', 'Spanish', 'Swedish'], |
||
| 84 | ], |
||
| 85 | 'newgroupscan_names' => ['Days', 'Posts'], |
||
| 86 | 'registerstatus' => [ |
||
| 87 | 'ids' => [Settings::REGISTER_STATUS_OPEN, Settings::REGISTER_STATUS_INVITE, Settings::REGISTER_STATUS_CLOSED], |
||
| 88 | 'names' => ['Open', 'Invite', 'Closed'], |
||
| 89 | ], |
||
| 90 | 'passworded' => [ |
||
| 91 | 'ids' => [0, 1], |
||
| 92 | 'names' => ['Hide passworded', 'Show everything'], |
||
| 93 | ], |
||
| 94 | 'lookuplanguage' => [ |
||
| 95 | 'iso' => ['en', 'de', 'es', 'fr', 'it', 'nl', 'pt', 'sv'], |
||
| 96 | 'names' => ['English', 'Deutsch', 'Español', 'Français', 'Italiano', 'Nederlands', 'Português', 'Svenska'], |
||
| 97 | ], |
||
| 98 | 'imdb_urls' => [ |
||
| 99 | 'ids' => [0, 1], |
||
| 100 | 'names' => ['imdb.com', 'akas.imdb.com'], |
||
| 101 | ], |
||
| 102 | 'lookupbooks' => [ |
||
| 103 | 'ids' => [0, 1, 2], |
||
| 104 | 'names' => ['Disabled', 'Lookup All Books', 'Lookup Renamed Books'], |
||
| 105 | ], |
||
| 106 | 'lookupgames' => [ |
||
| 107 | 'ids' => [0, 1, 2], |
||
| 108 | 'names' => ['Disabled', 'Lookup All Consoles', 'Lookup Renamed Consoles'], |
||
| 109 | ], |
||
| 110 | 'lookupmusic' => [ |
||
| 111 | 'ids' => [0, 1, 2], |
||
| 112 | 'names' => ['Disabled', 'Lookup All Music', 'Lookup Renamed Music'], |
||
| 113 | ], |
||
| 114 | 'lookupmovies' => [ |
||
| 115 | 'ids' => [0, 1, 2], |
||
| 116 | 'names' => ['Disabled', 'Lookup All Movies', 'Lookup Renamed Movies'], |
||
| 117 | ], |
||
| 118 | 'lookuptv' => [ |
||
| 119 | 'ids' => [0, 1, 2], |
||
| 120 | 'names' => ['Disabled', 'Lookup All TV', 'Lookup Renamed TV'], |
||
| 121 | ], |
||
| 122 | 'lookup_reqids' => [ |
||
| 123 | 'ids' => [0, 1, 2], |
||
| 124 | 'names' => ['Disabled', 'Lookup Request IDs', 'Lookup Request IDs Threaded'], |
||
| 125 | ], |
||
| 126 | 'book_reqids' => [ |
||
| 127 | 'ids' => $book_reqids_ids, |
||
| 128 | 'names' => $book_reqids_names, |
||
| 129 | 'selected' => $books_selected, |
||
| 130 | ], |
||
| 131 | 'compress_headers_warning' => $compress_headers_warning, |
||
| 132 | 'title' => $title, |
||
| 133 | 'meta_title' => $meta_title, |
||
| 134 | ]); |
||
| 135 | |||
| 136 | return view('admin.site.edit', $this->viewData); |
||
| 137 | } |
||
| 166 |