| Conditions | 11 |
| Paths | 8 |
| Total Lines | 87 |
| Code Lines | 60 |
| 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 |
||
| 155 | protected function main() |
||
| 156 | { |
||
| 157 | $lang = $this->getLanguageService(); |
||
| 158 | $assigns = [ |
||
| 159 | 'target' => $this->target, |
||
| 160 | 'confirmTitle' => $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:pleaseConfirm'), |
||
| 161 | 'confirmText' => $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:mess.redraw'), |
||
| 162 | 'selfUrl' => (string)$this->uriBuilder->buildUriFromRoute('file_newfolder', [ |
||
| 163 | 'target' => $this->target, |
||
| 164 | 'returnUrl' => $this->returnUrl, |
||
| 165 | 'number' => 'AMOUNT', |
||
| 166 | ]), |
||
| 167 | ]; |
||
| 168 | if ($this->folderObject->checkActionPermission('add')) { |
||
| 169 | $assigns['moduleUrlTceFile'] = (string)$this->uriBuilder->buildUriFromRoute('tce_file'); |
||
| 170 | $assigns['cshFileNewFolder'] = BackendUtility::cshItem('xMOD_csh_corebe', 'file_newfolder'); |
||
| 171 | // Making the selector box for the number of concurrent folder-creations |
||
| 172 | $this->number = MathUtility::forceIntegerInRange($this->number, 1, 10); |
||
| 173 | for ($a = 1; $a <= $this->folderNumber; $a++) { |
||
| 174 | $options = []; |
||
| 175 | $options['value'] = $a; |
||
| 176 | $options['selected'] = ($this->number == $a ? ' selected="selected"' : ''); |
||
| 177 | $assigns['options'][] = $options; |
||
| 178 | } |
||
| 179 | // Making the number of new-folder boxes needed: |
||
| 180 | for ($a = 0; $a < $this->number; $a++) { |
||
| 181 | $folder = []; |
||
| 182 | $folder['this'] = $a; |
||
| 183 | $folder['next'] = $a + 1; |
||
| 184 | $assigns['folders'][] = $folder; |
||
| 185 | } |
||
| 186 | // Making submit button for folder creation: |
||
| 187 | $assigns['returnUrl'] = $this->returnUrl; |
||
| 188 | } |
||
| 189 | |||
| 190 | if ($this->folderObject->getStorage()->checkUserActionPermission('add', 'File')) { |
||
| 191 | $assigns['moduleUrlOnlineMedia'] = (string)$this->uriBuilder->buildUriFromRoute('online_media'); |
||
| 192 | $assigns['cshFileNewMedia'] = BackendUtility::cshItem('xMOD_csh_corebe', 'file_newMedia'); |
||
| 193 | // Create a list of allowed file extensions with the readable format "youtube, vimeo" etc. |
||
| 194 | $fileExtList = []; |
||
| 195 | $onlineMediaFileExt = OnlineMediaHelperRegistry::getInstance()->getSupportedFileExtensions(); |
||
| 196 | $fileNameVerifier = GeneralUtility::makeInstance(FileNameValidator::class); |
||
| 197 | foreach ($onlineMediaFileExt as $fileExt) { |
||
| 198 | if ($fileNameVerifier->isValid('.' . $fileExt)) { |
||
| 199 | $fileExtList[] = strtoupper(htmlspecialchars($fileExt)); |
||
| 200 | } |
||
| 201 | } |
||
| 202 | $assigns['fileExtList'] = $fileExtList; |
||
| 203 | |||
| 204 | $assigns['moduleUrlTceFile'] = (string)$this->uriBuilder->buildUriFromRoute('tce_file'); |
||
| 205 | $assigns['cshFileNewFile'] = BackendUtility::cshItem('xMOD_csh_corebe', 'file_newfile'); |
||
| 206 | // Create a list of allowed file extensions with a text format "*.txt, *.css" etc. |
||
| 207 | $fileExtList = []; |
||
| 208 | $textFileExt = GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], true); |
||
| 209 | foreach ($textFileExt as $fileExt) { |
||
| 210 | if ($fileNameVerifier->isValid('.' . $fileExt)) { |
||
| 211 | $fileExtList[] = strtoupper(htmlspecialchars($fileExt)); |
||
| 212 | } |
||
| 213 | } |
||
| 214 | $assigns['txtFileExtList'] = $fileExtList; |
||
| 215 | } |
||
| 216 | |||
| 217 | $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar(); |
||
| 218 | // CSH button |
||
| 219 | $helpButton = $buttonBar->makeHelpButton() |
||
| 220 | ->setFieldName('file_new') |
||
| 221 | ->setModuleName('xMOD_csh_corebe'); |
||
| 222 | $buttonBar->addButton($helpButton); |
||
| 223 | |||
| 224 | // Back |
||
| 225 | if ($this->returnUrl) { |
||
| 226 | $backButton = $buttonBar->makeLinkButton() |
||
| 227 | ->setHref($this->returnUrl) |
||
| 228 | ->setTitle($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.goBack')) |
||
| 229 | ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-view-go-back', Icon::SIZE_SMALL)); |
||
| 230 | $buttonBar->addButton($backButton); |
||
| 231 | } |
||
| 232 | |||
| 233 | // Rendering of the output via fluid |
||
| 234 | $view = GeneralUtility::makeInstance(StandaloneView::class); |
||
| 235 | $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates')]); |
||
| 236 | $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Partials')]); |
||
| 237 | $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName( |
||
| 238 | 'EXT:filelist/Resources/Private/Templates/File/CreateFolder.html' |
||
| 239 | )); |
||
| 240 | $view->assignMultiple($assigns); |
||
| 241 | $this->moduleTemplate->setContent($view->render()); |
||
| 242 | } |
||
| 254 |