| Conditions | 20 |
| Paths | 7682 |
| Total Lines | 152 |
| Code Lines | 102 |
| 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 |
||
| 186 | public function index($dir = '', $view = '', $fileid = null, $fileNotFound = false, $openfile = null) { |
||
| 187 | if ($fileid !== null) { |
||
| 188 | try { |
||
| 189 | return $this->redirectToFile($fileid); |
||
| 190 | } catch (NotFoundException $e) { |
||
| 191 | return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true])); |
||
| 192 | } |
||
| 193 | } |
||
| 194 | |||
| 195 | $nav = new \OCP\Template('files', 'appnavigation', ''); |
||
| 196 | |||
| 197 | // Load the files we need |
||
| 198 | \OCP\Util::addStyle('files', 'merged'); |
||
| 199 | \OCP\Util::addScript('files', 'merged-index'); |
||
| 200 | \OCP\Util::addScript('files', 'dist/templates'); |
||
| 201 | |||
| 202 | // mostly for the home storage's free space |
||
| 203 | // FIXME: Make non static |
||
| 204 | $storageInfo = $this->getStorageInfo(); |
||
| 205 | |||
| 206 | $user = $this->userSession->getUser()->getUID(); |
||
| 207 | |||
| 208 | // Get all the user favorites to create a submenu |
||
| 209 | try { |
||
| 210 | $favElements = $this->activityHelper->getFavoriteFilePaths($this->userSession->getUser()->getUID()); |
||
| 211 | } catch (\RuntimeException $e) { |
||
| 212 | $favElements['folders'] = []; |
||
| 213 | } |
||
| 214 | |||
| 215 | $collapseClasses = ''; |
||
| 216 | if (count($favElements['folders']) > 0) { |
||
| 217 | $collapseClasses = 'collapsible'; |
||
| 218 | } |
||
| 219 | |||
| 220 | $favoritesSublistArray = []; |
||
| 221 | |||
| 222 | $navBarPositionPosition = 6; |
||
| 223 | $currentCount = 0; |
||
| 224 | foreach ($favElements['folders'] as $dir) { |
||
| 225 | $link = $this->urlGenerator->linkToRoute('files.view.index', ['dir' => $dir, 'view' => 'files']); |
||
| 226 | $sortingValue = ++$currentCount; |
||
| 227 | $element = [ |
||
| 228 | 'id' => str_replace('/', '-', $dir), |
||
| 229 | 'view' => 'files', |
||
| 230 | 'href' => $link, |
||
| 231 | 'dir' => $dir, |
||
| 232 | 'order' => $navBarPositionPosition, |
||
| 233 | 'folderPosition' => $sortingValue, |
||
| 234 | 'name' => basename($dir), |
||
| 235 | 'icon' => 'files', |
||
| 236 | 'quickaccesselement' => 'true' |
||
| 237 | ]; |
||
| 238 | |||
| 239 | array_push($favoritesSublistArray, $element); |
||
| 240 | $navBarPositionPosition++; |
||
| 241 | } |
||
| 242 | |||
| 243 | $navItems = \OCA\Files\App::getNavigationManager()->getAll(); |
||
| 244 | |||
| 245 | // add the favorites entry in menu |
||
| 246 | $navItems['favorites']['sublist'] = $favoritesSublistArray; |
||
| 247 | $navItems['favorites']['classes'] = $collapseClasses; |
||
| 248 | |||
| 249 | // parse every menu and add the expandedState user value |
||
| 250 | foreach ($navItems as $key => $item) { |
||
| 251 | if (isset($item['expandedState'])) { |
||
| 252 | $navItems[$key]['defaultExpandedState'] = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', $item['expandedState'], '0') === '1'; |
||
| 253 | } |
||
| 254 | } |
||
| 255 | |||
| 256 | $nav->assign('navigationItems', $navItems); |
||
| 257 | |||
| 258 | $nav->assign('usage', \OC_Helper::humanFileSize($storageInfo['used'])); |
||
| 259 | if ($storageInfo['quota'] === \OCP\Files\FileInfo::SPACE_UNLIMITED) { |
||
| 260 | $totalSpace = $this->l10n->t('Unlimited'); |
||
| 261 | } else { |
||
| 262 | $totalSpace = \OC_Helper::humanFileSize($storageInfo['total']); |
||
| 263 | } |
||
| 264 | $nav->assign('total_space', $totalSpace); |
||
| 265 | $nav->assign('quota', $storageInfo['quota']); |
||
| 266 | $nav->assign('usage_relative', $storageInfo['relative']); |
||
| 267 | |||
| 268 | $nav->assign('webdav_url', \OCP\Util::linkToRemote('dav/files/' . $user)); |
||
| 269 | |||
| 270 | $contentItems = []; |
||
| 271 | |||
| 272 | // render the container content for every navigation item |
||
| 273 | foreach ($navItems as $item) { |
||
| 274 | $content = ''; |
||
| 275 | if (isset($item['script'])) { |
||
| 276 | $content = $this->renderScript($item['appname'], $item['script']); |
||
| 277 | } |
||
| 278 | // parse submenus |
||
| 279 | if (isset($item['sublist'])) { |
||
| 280 | foreach ($item['sublist'] as $subitem) { |
||
| 281 | $subcontent = ''; |
||
| 282 | if (isset($subitem['script'])) { |
||
| 283 | $subcontent = $this->renderScript($subitem['appname'], $subitem['script']); |
||
| 284 | } |
||
| 285 | $contentItems[$subitem['id']] = [ |
||
| 286 | 'id' => $subitem['id'], |
||
| 287 | 'content' => $subcontent |
||
| 288 | ]; |
||
| 289 | } |
||
| 290 | } |
||
| 291 | $contentItems[$item['id']] = [ |
||
| 292 | 'id' => $item['id'], |
||
| 293 | 'content' => $content |
||
| 294 | ]; |
||
| 295 | } |
||
| 296 | |||
| 297 | $event = new LoadAdditionalScriptsEvent(); |
||
| 298 | $this->eventDispatcher->dispatchTyped($event); |
||
| 299 | $this->eventDispatcher->dispatchTyped(new LoadSidebar()); |
||
| 300 | // Load Viewer scripts |
||
| 301 | if (class_exists(LoadViewer::class)) { |
||
| 302 | $this->eventDispatcher->dispatchTyped(new LoadViewer()); |
||
| 303 | } |
||
| 304 | $this->initialState->provideInitialState('templates_path', $this->templateManager->hasTemplateDirectory() ? $this->templateManager->getTemplatePath() : false); |
||
| 305 | $this->initialState->provideInitialState('templates', $this->templateManager->listCreators()); |
||
| 306 | |||
| 307 | $params = []; |
||
| 308 | $params['usedSpacePercent'] = (int) $storageInfo['relative']; |
||
| 309 | $params['owner'] = $storageInfo['owner'] ?? ''; |
||
| 310 | $params['ownerDisplayName'] = $storageInfo['ownerDisplayName'] ?? ''; |
||
| 311 | $params['isPublic'] = false; |
||
| 312 | $params['allowShareWithLink'] = $this->shareManager->shareApiAllowLinks() ? 'yes' : 'no'; |
||
| 313 | $params['defaultFileSorting'] = $this->config->getUserValue($user, 'files', 'file_sorting', 'name'); |
||
| 314 | $params['defaultFileSortingDirection'] = $this->config->getUserValue($user, 'files', 'file_sorting_direction', 'asc'); |
||
| 315 | $params['showgridview'] = $this->config->getUserValue($user, 'files', 'show_grid', false); |
||
| 316 | $params['isIE'] = \OC_Util::isIe(); |
||
| 317 | $showHidden = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', false); |
||
| 318 | $params['showHiddenFiles'] = $showHidden ? 1 : 0; |
||
| 319 | $cropImagePreviews = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'crop_image_previews', true); |
||
| 320 | $params['cropImagePreviews'] = $cropImagePreviews ? 1 : 0; |
||
| 321 | $params['fileNotFound'] = $fileNotFound ? 1 : 0; |
||
| 322 | $params['appNavigation'] = $nav; |
||
| 323 | $params['appContents'] = $contentItems; |
||
| 324 | $params['hiddenFields'] = $event->getHiddenFields(); |
||
| 325 | |||
| 326 | $response = new TemplateResponse( |
||
| 327 | $this->appName, |
||
| 328 | 'index', |
||
| 329 | $params |
||
| 330 | ); |
||
| 331 | $policy = new ContentSecurityPolicy(); |
||
| 332 | $policy->addAllowedFrameDomain('\'self\''); |
||
| 333 | $response->setContentSecurityPolicy($policy); |
||
| 334 | |||
| 335 | $this->provideInitialState($dir, $openfile); |
||
| 336 | |||
| 337 | return $response; |
||
| 338 | } |
||
| 426 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths