| Conditions | 5 |
| Paths | 6 |
| Total Lines | 64 |
| Code Lines | 41 |
| 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 |
||
| 77 | public function export(Request $request) |
||
| 78 | { |
||
| 79 | if (Utility::isCLI()) { |
||
| 80 | exit('This script is only for exporting from the web, use the script in misc/testing'. |
||
| 81 | PHP_EOL); |
||
| 82 | } |
||
| 83 | |||
| 84 | $this->setAdminPrefs(); |
||
| 85 | $rel = new Releases(); |
||
| 86 | |||
| 87 | if ($this->isPostBack()) { |
||
| 88 | $path = $request->input('folder'); |
||
| 89 | $postFrom = ($request->input('postfrom') ?? ''); |
||
| 90 | $postTo = ($request->input('postto') ?? ''); |
||
| 91 | $group = ($request->input('group') === '-1' ? 0 : (int) $request->input('group')); |
||
| 92 | $gzip = ($request->input('gzip') === '1'); |
||
| 93 | |||
| 94 | if ($path !== '') { |
||
| 95 | $NE = new NZBExport([ |
||
| 96 | 'Browser' => true, 'Settings' => null, |
||
| 97 | 'Releases' => $rel, |
||
| 98 | ]); |
||
| 99 | $retVal = $NE->beginExport( |
||
| 100 | [ |
||
| 101 | $path, |
||
| 102 | $postFrom, |
||
| 103 | $postTo, |
||
| 104 | $group, |
||
| 105 | $gzip, |
||
| 106 | ] |
||
| 107 | ); |
||
| 108 | } else { |
||
| 109 | $retVal = 'Error, a path is required!'; |
||
| 110 | } |
||
| 111 | |||
| 112 | $this->smarty->assign( |
||
| 113 | [ |
||
| 114 | 'folder' => $path, |
||
| 115 | 'output' => $retVal, |
||
| 116 | 'fromdate' => $postFrom, |
||
| 117 | 'todate' => $postTo, |
||
| 118 | 'group' => $request->input('group'), |
||
| 119 | 'gzip' => $request->input('gzip'), |
||
| 120 | ] |
||
| 121 | ); |
||
| 122 | } else { |
||
| 123 | $this->smarty->assign( |
||
| 124 | [ |
||
| 125 | 'fromdate' => $rel->getEarliestUsenetPostDate(), |
||
| 126 | 'todate' => $rel->getLatestUsenetPostDate(), |
||
| 127 | ] |
||
| 128 | ); |
||
| 129 | } |
||
| 130 | |||
| 131 | $meta_title = $title = 'Export Nzbs'; |
||
| 132 | $this->smarty->assign( |
||
| 133 | [ |
||
| 134 | 'gziplist' => [1 => 'True', 0 => 'False'], |
||
| 135 | 'grouplist' => $rel->getReleasedGroupsForSelect(true), |
||
| 136 | ] |
||
| 137 | ); |
||
| 138 | $content = $this->smarty->fetch('nzb-export.tpl'); |
||
| 139 | $this->smarty->assign(compact('title', 'meta_title', 'content')); |
||
| 140 | $this->adminrender(); |
||
| 141 | } |
||
| 143 |