| Conditions | 10 |
| Paths | 35 |
| Total Lines | 51 |
| Code Lines | 27 |
| 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 |
||
| 19 | public function import(Request $request) |
||
| 20 | { |
||
| 21 | $this->setAdminPrefs(); |
||
| 22 | |||
| 23 | $filesToProcess = []; |
||
| 24 | if ($this->isPostBack()) { |
||
| 25 | $useNzbName = false; |
||
| 26 | $deleteNZB = true; |
||
| 27 | // Get the list of NZB files from php /tmp folder if nzb files were uploaded. |
||
| 28 | if (isset($_FILES['uploadedfiles'])) { |
||
| 29 | foreach ($_FILES['uploadedfiles']['error'] as $key => $error) { |
||
| 30 | if ($error === UPLOAD_ERR_OK) { |
||
| 31 | $tmp_name = $_FILES['uploadedfiles']['tmp_name'][$key]; |
||
| 32 | $name = $_FILES['uploadedfiles']['name'][$key]; |
||
|
|
|||
| 33 | $filesToProcess[] = $tmp_name; |
||
| 34 | } |
||
| 35 | } |
||
| 36 | } else { |
||
| 37 | |||
| 38 | // Check if the user wants to use the file name as the release name. |
||
| 39 | $useNzbName = ($request->has('usefilename') && $request->input('usefilename') === 'on'); |
||
| 40 | |||
| 41 | // Check if the user wants to delete the NZB file when done importing. |
||
| 42 | $deleteNZB = ($request->has('deleteNZB') && $request->input('deleteNZB') === 'on'); |
||
| 43 | |||
| 44 | // Get the path the user set in the browser if he put one. |
||
| 45 | $path = ($request->has('folder') ? $request->input('folder') : ''); |
||
| 46 | if (substr($path, \strlen($path) - 1) !== DS) { |
||
| 47 | $path .= DS; |
||
| 48 | } |
||
| 49 | |||
| 50 | // Get the files from the user specified path. |
||
| 51 | $filesToProcess = glob($path.'*.nzb'); |
||
| 52 | } |
||
| 53 | |||
| 54 | if (\count($filesToProcess) > 0) { |
||
| 55 | |||
| 56 | // Create a new instance of NZBImport and send it the file locations. |
||
| 57 | $NZBImport = new NZBImport(['Browser' => true, 'Settings' => null]); |
||
| 58 | |||
| 59 | $this->smarty->assign( |
||
| 60 | 'output', |
||
| 61 | $NZBImport->beginImport($filesToProcess, $useNzbName, $deleteNZB) |
||
| 62 | ); |
||
| 63 | } |
||
| 64 | } |
||
| 65 | |||
| 66 | $meta_title = $title = 'Import Nzbs'; |
||
| 67 | $content = $this->smarty->fetch('nzb-import.tpl'); |
||
| 68 | $this->smarty->assign(compact('title', 'meta_title', 'content')); |
||
| 69 | $this->adminrender(); |
||
| 70 | } |
||
| 143 |