| Conditions | 11 |
| Paths | 15 |
| Total Lines | 116 |
| Code Lines | 84 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 141 | public function index($dir = '', $view = '', $fileid = null) { |
||
| 142 | if ($fileid !== null) { |
||
| 143 | return $this->showFile($fileid); |
||
| 144 | } |
||
| 145 | |||
| 146 | $nav = new \OCP\Template('files', 'appnavigation', ''); |
||
| 147 | |||
| 148 | // Load the files we need |
||
| 149 | \OCP\Util::addStyle('files', 'files'); |
||
| 150 | \OCP\Util::addStyle('files', 'upload'); |
||
| 151 | \OCP\Util::addStyle('files', 'mobile'); |
||
| 152 | \OCP\Util::addscript('files', 'app'); |
||
| 153 | \OCP\Util::addscript('files', 'file-upload'); |
||
| 154 | \OCP\Util::addscript('files', 'newfilemenu'); |
||
| 155 | \OCP\Util::addscript('files', 'jquery.fileupload'); |
||
| 156 | \OCP\Util::addscript('files', 'jquery-visibility'); |
||
| 157 | \OCP\Util::addscript('files', 'fileinfomodel'); |
||
| 158 | \OCP\Util::addscript('files', 'filesummary'); |
||
| 159 | \OCP\Util::addscript('files', 'breadcrumb'); |
||
| 160 | \OCP\Util::addscript('files', 'filelist'); |
||
| 161 | \OCP\Util::addscript('files', 'search'); |
||
| 162 | |||
| 163 | \OCP\Util::addScript('files', 'favoritesfilelist'); |
||
| 164 | \OCP\Util::addScript('files', 'tagsplugin'); |
||
| 165 | \OCP\Util::addScript('files', 'favoritesplugin'); |
||
| 166 | |||
| 167 | \OCP\Util::addScript('files', 'detailfileinfoview'); |
||
| 168 | \OCP\Util::addScript('files', 'detailtabview'); |
||
| 169 | \OCP\Util::addScript('files', 'mainfileinfodetailview'); |
||
| 170 | \OCP\Util::addScript('files', 'detailsview'); |
||
| 171 | \OCP\Util::addStyle('files', 'detailsView'); |
||
| 172 | |||
| 173 | \OC_Util::addVendorScript('core', 'handlebars/handlebars'); |
||
| 174 | |||
| 175 | \OCP\Util::addscript('files', 'fileactions'); |
||
| 176 | \OCP\Util::addscript('files', 'fileactionsmenu'); |
||
| 177 | \OCP\Util::addscript('files', 'files'); |
||
| 178 | \OCP\Util::addscript('files', 'keyboardshortcuts'); |
||
| 179 | \OCP\Util::addscript('files', 'navigation'); |
||
| 180 | |||
| 181 | // if IE8 and "?dir=path&view=someview" was specified, reformat the URL to use a hash like "#?dir=path&view=someview" |
||
| 182 | $isIE8 = $this->request->isUserAgent([Request::USER_AGENT_IE_8]); |
||
| 183 | if ($isIE8 && ($dir !== '' || $view !== '')) { |
||
| 184 | $dir = !empty($dir) ? $dir : '/'; |
||
| 185 | $view = !empty($view) ? $view : 'files'; |
||
| 186 | $hash = '#?dir=' . \OCP\Util::encodePath($dir); |
||
| 187 | if ($view !== 'files') { |
||
| 188 | $hash .= '&view=' . urlencode($view); |
||
| 189 | } |
||
| 190 | return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index') . $hash); |
||
| 191 | } |
||
| 192 | |||
| 193 | // mostly for the home storage's free space |
||
| 194 | // FIXME: Make non static |
||
| 195 | $storageInfo = $this->getStorageInfo(); |
||
| 196 | |||
| 197 | \OCA\Files\App::getNavigationManager()->add( |
||
| 198 | [ |
||
| 199 | 'id' => 'favorites', |
||
| 200 | 'appname' => 'files', |
||
| 201 | 'script' => 'simplelist.php', |
||
| 202 | 'order' => 5, |
||
| 203 | 'name' => $this->l10n->t('Favorites') |
||
| 204 | ] |
||
| 205 | ); |
||
| 206 | |||
| 207 | $navItems = \OCA\Files\App::getNavigationManager()->getAll(); |
||
| 208 | usort($navItems, function($item1, $item2) { |
||
| 209 | return $item1['order'] - $item2['order']; |
||
| 210 | }); |
||
| 211 | $nav->assign('navigationItems', $navItems); |
||
| 212 | |||
| 213 | $contentItems = []; |
||
| 214 | |||
| 215 | // render the container content for every navigation item |
||
| 216 | foreach ($navItems as $item) { |
||
| 217 | $content = ''; |
||
| 218 | if (isset($item['script'])) { |
||
| 219 | $content = $this->renderScript($item['appname'], $item['script']); |
||
| 220 | } |
||
| 221 | $contentItem = []; |
||
| 222 | $contentItem['id'] = $item['id']; |
||
| 223 | $contentItem['content'] = $content; |
||
| 224 | $contentItems[] = $contentItem; |
||
| 225 | } |
||
| 226 | |||
| 227 | $this->eventDispatcher->dispatch('OCA\Files::loadAdditionalScripts'); |
||
| 228 | |||
| 229 | $params = []; |
||
| 230 | $params['usedSpacePercent'] = (int)$storageInfo['relative']; |
||
| 231 | $params['owner'] = $storageInfo['owner']; |
||
| 232 | $params['ownerDisplayName'] = $storageInfo['ownerDisplayName']; |
||
| 233 | $params['isPublic'] = false; |
||
| 234 | $params['mailNotificationEnabled'] = $this->config->getAppValue('core', 'shareapi_allow_mail_notification', 'no'); |
||
| 235 | $params['mailPublicNotificationEnabled'] = $this->config->getAppValue('core', 'shareapi_allow_public_notification', 'no'); |
||
| 236 | $params['allowShareWithLink'] = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes'); |
||
| 237 | $user = $this->userSession->getUser()->getUID(); |
||
| 238 | $params['defaultFileSorting'] = $this->config->getUserValue($user, 'files', 'file_sorting', 'name'); |
||
| 239 | $params['defaultFileSortingDirection'] = $this->config->getUserValue($user, 'files', 'file_sorting_direction', 'asc'); |
||
| 240 | $showHidden = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', false); |
||
| 241 | $params['showHiddenFiles'] = $showHidden ? 1 : 0; |
||
| 242 | $params['appNavigation'] = $nav; |
||
| 243 | $params['appContents'] = $contentItems; |
||
| 244 | $this->navigationManager->setActiveEntry('files_index'); |
||
| 245 | |||
| 246 | $response = new TemplateResponse( |
||
| 247 | $this->appName, |
||
| 248 | 'index', |
||
| 249 | $params |
||
| 250 | ); |
||
| 251 | $policy = new ContentSecurityPolicy(); |
||
| 252 | $policy->addAllowedFrameDomain('\'self\''); |
||
| 253 | $response->setContentSecurityPolicy($policy); |
||
| 254 | |||
| 255 | return $response; |
||
| 256 | } |
||
| 257 | |||
| 287 |
If you suppress an error, we recommend checking for the error condition explicitly: