| Conditions | 16 |
| Paths | 108 |
| Total Lines | 158 |
| Code Lines | 101 |
| 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 |
||
| 22 | public function edit(Request $request) |
||
| 23 | { |
||
| 24 | $this->setAdminPrefs(); |
||
| 25 | |||
| 26 | $meta_title = $title = 'Site Edit'; |
||
| 27 | |||
| 28 | // set the current action |
||
| 29 | $action = $request->input('action') ?? 'view'; |
||
| 30 | |||
| 31 | switch ($action) { |
||
| 32 | case 'submit': |
||
| 33 | if ($request->missing('book_reqids')) { |
||
| 34 | $request->merge(['book_reqids' => []]); |
||
| 35 | } |
||
| 36 | $error = ''; |
||
| 37 | $ret = Settings::settingsUpdate($request->all()); |
||
|
|
|||
| 38 | if (\is_int($ret)) { |
||
| 39 | if ($ret === Settings::ERR_BADUNRARPATH) { |
||
| 40 | $error = 'The unrar path does not point to a valid binary'; |
||
| 41 | } elseif ($ret === Settings::ERR_BADFFMPEGPATH) { |
||
| 42 | $error = 'The ffmpeg path does not point to a valid binary'; |
||
| 43 | } elseif ($ret === Settings::ERR_BADMEDIAINFOPATH) { |
||
| 44 | $error = 'The mediainfo path does not point to a valid binary'; |
||
| 45 | } elseif ($ret === Settings::ERR_BADNZBPATH) { |
||
| 46 | $error = 'The nzb path does not point to a valid directory'; |
||
| 47 | } elseif ($ret === Settings::ERR_DEEPNOUNRAR) { |
||
| 48 | $error = 'Deep password check requires a valid path to unrar binary'; |
||
| 49 | } elseif ($ret === Settings::ERR_BADTMPUNRARPATH) { |
||
| 50 | $error = 'The temp unrar path is not a valid directory'; |
||
| 51 | } elseif ($ret === Settings::ERR_BADLAMEPATH) { |
||
| 52 | $error = 'The lame path is not a valid directory'; |
||
| 53 | } elseif ($ret === Settings::ERR_SABCOMPLETEPATH) { |
||
| 54 | $error = 'The sab complete path is not a valid directory'; |
||
| 55 | } |
||
| 56 | } |
||
| 57 | |||
| 58 | if ($error === '') { |
||
| 59 | $site = $ret; |
||
| 60 | |||
| 61 | return redirect('admin/site-edit'); |
||
| 62 | } |
||
| 63 | |||
| 64 | $this->smarty->assign('error', $error); |
||
| 65 | $site = (object) $request->all(); |
||
| 66 | $this->smarty->assign('site', $site); |
||
| 67 | |||
| 68 | break; |
||
| 69 | case 'view': |
||
| 70 | default: |
||
| 71 | $site = $this->settings; |
||
| 72 | $this->smarty->assign('site', $site); |
||
| 73 | $this->smarty->assign('settings', Settings::toTree()); |
||
| 74 | break; |
||
| 75 | } |
||
| 76 | |||
| 77 | $this->smarty->assign('yesno_ids', [1, 0]); |
||
| 78 | $this->smarty->assign('yesno_names', ['Yes', 'No']); |
||
| 79 | |||
| 80 | $this->smarty->assign('passwd_ids', [1, 0]); |
||
| 81 | $this->smarty->assign('passwd_names', ['Deep (requires unrar)', 'None']); |
||
| 82 | |||
| 83 | /*0 = English, 2 = Danish, 3 = French, 1 = German*/ |
||
| 84 | $this->smarty->assign('langlist_ids', [0, 2, 3, 1]); |
||
| 85 | $this->smarty->assign('langlist_names', ['English', 'Danish', 'French', 'German']); |
||
| 86 | |||
| 87 | $this->smarty->assign( |
||
| 88 | 'imdblang_ids', |
||
| 89 | [ |
||
| 90 | 'en', 'da', 'nl', 'fi', 'fr', 'de', 'it', 'tlh', 'no', 'po', 'ru', 'es', |
||
| 91 | 'sv', |
||
| 92 | ] |
||
| 93 | ); |
||
| 94 | $this->smarty->assign( |
||
| 95 | 'imdblang_names', |
||
| 96 | [ |
||
| 97 | 'English', 'Danish', 'Dutch', 'Finnish', 'French', 'German', 'Italian', |
||
| 98 | 'Klingon', 'Norwegian', 'Polish', 'Russian', 'Spanish', 'Swedish', |
||
| 99 | ] |
||
| 100 | ); |
||
| 101 | |||
| 102 | $this->smarty->assign('sabintegrationtype_ids', [SABnzbd::INTEGRATION_TYPE_USER, SABnzbd::INTEGRATION_TYPE_NONE]); |
||
| 103 | $this->smarty->assign('sabintegrationtype_names', ['User', 'None (Off)']); |
||
| 104 | |||
| 105 | $this->smarty->assign('newgroupscan_names', ['Days', 'Posts']); |
||
| 106 | |||
| 107 | $this->smarty->assign('registerstatus_ids', [Settings::REGISTER_STATUS_OPEN, Settings::REGISTER_STATUS_INVITE, Settings::REGISTER_STATUS_CLOSED]); |
||
| 108 | $this->smarty->assign('registerstatus_names', ['Open', 'Invite', 'Closed']); |
||
| 109 | |||
| 110 | $this->smarty->assign('passworded_ids', [0, 1]); |
||
| 111 | $this->smarty->assign('passworded_names', [ |
||
| 112 | 'Hide passworded', |
||
| 113 | 'Show everything', |
||
| 114 | ]); |
||
| 115 | |||
| 116 | $this->smarty->assign('lookuplanguage_iso', ['en', 'de', 'es', 'fr', 'it', 'nl', 'pt', 'sv']); |
||
| 117 | $this->smarty->assign('lookuplanguage_names', ['English', 'Deutsch', 'Español', 'Français', 'Italiano', 'Nederlands', 'Português', 'Svenska']); |
||
| 118 | |||
| 119 | $this->smarty->assign('imdb_urls', [0, 1]); |
||
| 120 | $this->smarty->assign('imdburl_names', ['imdb.com', 'akas.imdb.com']); |
||
| 121 | |||
| 122 | $this->smarty->assign('lookupbooks_ids', [0, 1, 2]); |
||
| 123 | $this->smarty->assign('lookupbooks_names', ['Disabled', 'Lookup All Books', 'Lookup Renamed Books']); |
||
| 124 | |||
| 125 | $this->smarty->assign('lookupgames_ids', [0, 1, 2]); |
||
| 126 | $this->smarty->assign('lookupgames_names', ['Disabled', 'Lookup All Consoles', 'Lookup Renamed Consoles']); |
||
| 127 | |||
| 128 | $this->smarty->assign('lookupmusic_ids', [0, 1, 2]); |
||
| 129 | $this->smarty->assign('lookupmusic_names', ['Disabled', 'Lookup All Music', 'Lookup Renamed Music']); |
||
| 130 | |||
| 131 | $this->smarty->assign('lookupmovies_ids', [0, 1, 2]); |
||
| 132 | $this->smarty->assign('lookupmovies_names', ['Disabled', 'Lookup All Movies', 'Lookup Renamed Movies']); |
||
| 133 | |||
| 134 | $this->smarty->assign('lookuptv_ids', [0, 1, 2]); |
||
| 135 | $this->smarty->assign('lookuptv_names', ['Disabled', 'Lookup All TV', 'Lookup Renamed TV']); |
||
| 136 | |||
| 137 | $this->smarty->assign('lookup_reqids_ids', [0, 1, 2]); |
||
| 138 | $this->smarty->assign('lookup_reqids_names', ['Disabled', 'Lookup Request IDs', 'Lookup Request IDs Threaded']); |
||
| 139 | |||
| 140 | $this->smarty->assign('coversPath', NN_COVERS); |
||
| 141 | |||
| 142 | // return a list of audiobooks, mags, ebooks, technical and foreign books |
||
| 143 | $result = Category::query()->whereIn('id', [Category::MUSIC_AUDIOBOOK, Category::BOOKS_MAGAZINES, Category::BOOKS_TECHNICAL, Category::BOOKS_FOREIGN])->get(['id', 'title']); |
||
| 144 | |||
| 145 | // setup the display lists for these categories, this could have been static, but then if names changed they would be wrong |
||
| 146 | $book_reqids_ids = []; |
||
| 147 | $book_reqids_names = []; |
||
| 148 | foreach ($result as $bookcategory) { |
||
| 149 | $book_reqids_ids[] = $bookcategory['id']; |
||
| 150 | $book_reqids_names[] = $bookcategory['title']; |
||
| 151 | } |
||
| 152 | |||
| 153 | // convert from a string array to an int array as we want to use int |
||
| 154 | $book_reqids_ids = array_map(function ($value) { |
||
| 155 | return (int) $value; |
||
| 156 | }, $book_reqids_ids); |
||
| 157 | $this->smarty->assign('book_reqids_ids', $book_reqids_ids); |
||
| 158 | $this->smarty->assign('book_reqids_names', $book_reqids_names); |
||
| 159 | |||
| 160 | // convert from a list to an array as we need to use an array, but teh Settings table only saves strings |
||
| 161 | $books_selected = explode(',', Settings::settingValue('..book_reqids')); |
||
| 162 | |||
| 163 | // convert from a string array to an int array |
||
| 164 | $books_selected = array_map(function ($value) { |
||
| 165 | return (int) $value; |
||
| 166 | }, $books_selected); |
||
| 167 | $this->smarty->assign('book_reqids_selected', $books_selected); |
||
| 168 | |||
| 169 | $this->smarty->assign('themelist', Utility::getThemesList()); |
||
| 170 | |||
| 171 | if (strpos(env('NNTP_SERVER'), 'astra') === false) { |
||
| 172 | $this->smarty->assign('compress_headers_warning', 'compress_headers_warning'); |
||
| 173 | } |
||
| 174 | |||
| 175 | $content = $this->smarty->fetch('site-edit.tpl'); |
||
| 176 | |||
| 177 | $this->smarty->assign(compact('title', 'meta_title', 'content')); |
||
| 178 | |||
| 179 | $this->adminrender(); |
||
| 180 | } |
||
| 218 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.