| Conditions | 34 |
| Paths | > 20000 |
| Total Lines | 208 |
| Code Lines | 138 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| Bugs | 0 | Features | 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 |
||
| 76 | public function __construct($renderAs, $appId = '') { |
||
| 77 | |||
| 78 | /** @var IConfig */ |
||
| 79 | $this->config = \OC::$server->get(IConfig::class); |
||
|
|
|||
| 80 | |||
| 81 | /** @var IInitialStateService */ |
||
| 82 | $this->initialState = \OC::$server->get(IInitialStateService::class); |
||
| 83 | |||
| 84 | // Add fallback theming variables if theming is disabled |
||
| 85 | if ($renderAs !== TemplateResponse::RENDER_AS_USER |
||
| 86 | || !\OC::$server->getAppManager()->isEnabledForUser('theming')) { |
||
| 87 | // TODO cache generated default theme if enabled for fallback if server is erroring ? |
||
| 88 | Util::addStyle('theming', 'default'); |
||
| 89 | } |
||
| 90 | |||
| 91 | // Decide which page we show |
||
| 92 | if ($renderAs === TemplateResponse::RENDER_AS_USER) { |
||
| 93 | /** @var INavigationManager */ |
||
| 94 | $this->navigationManager = \OC::$server->get(INavigationManager::class); |
||
| 95 | |||
| 96 | parent::__construct('core', 'layout.user'); |
||
| 97 | if (in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) { |
||
| 98 | $this->assign('bodyid', 'body-settings'); |
||
| 99 | } else { |
||
| 100 | $this->assign('bodyid', 'body-user'); |
||
| 101 | } |
||
| 102 | |||
| 103 | $this->initialState->provideInitialState('core', 'active-app', $this->navigationManager->getActiveEntry()); |
||
| 104 | $this->initialState->provideInitialState('unified-search', 'limit-default', (int)$this->config->getAppValue('core', 'unified-search.limit-default', (string)SearchQuery::LIMIT_DEFAULT)); |
||
| 105 | $this->initialState->provideInitialState('unified-search', 'min-search-length', (int)$this->config->getAppValue('core', 'unified-search.min-search-length', (string)2)); |
||
| 106 | $this->initialState->provideInitialState('unified-search', 'live-search', $this->config->getAppValue('core', 'unified-search.live-search', 'yes') === 'yes'); |
||
| 107 | Util::addScript('core', 'unified-search', 'core'); |
||
| 108 | |||
| 109 | // Set body data-theme |
||
| 110 | if (\OC::$server->getAppManager()->isEnabledForUser('theming') && class_exists('\OCA\Theming\Service\ThemesService')) { |
||
| 111 | /** @var \OCA\Theming\Service\ThemesService */ |
||
| 112 | $themesService = \OC::$server->get(\OCA\Theming\Service\ThemesService::class); |
||
| 113 | $this->assign('enabledThemes', $themesService->getEnabledThemes()); |
||
| 114 | } |
||
| 115 | |||
| 116 | // set logo link target |
||
| 117 | $logoUrl = $this->config->getSystemValueString('logo_url', ''); |
||
| 118 | $this->assign('logoUrl', $logoUrl); |
||
| 119 | |||
| 120 | // Add navigation entry |
||
| 121 | $this->assign('application', ''); |
||
| 122 | $this->assign('appid', $appId); |
||
| 123 | |||
| 124 | $navigation = $this->navigationManager->getAll(); |
||
| 125 | $this->assign('navigation', $navigation); |
||
| 126 | $settingsNavigation = $this->navigationManager->getAll('settings'); |
||
| 127 | $this->assign('settingsnavigation', $settingsNavigation); |
||
| 128 | |||
| 129 | foreach ($navigation as $entry) { |
||
| 130 | if ($entry['active']) { |
||
| 131 | $this->assign('application', $entry['name']); |
||
| 132 | break; |
||
| 133 | } |
||
| 134 | } |
||
| 135 | |||
| 136 | foreach ($settingsNavigation as $entry) { |
||
| 137 | if ($entry['active']) { |
||
| 138 | $this->assign('application', $entry['name']); |
||
| 139 | break; |
||
| 140 | } |
||
| 141 | } |
||
| 142 | |||
| 143 | $userDisplayName = false; |
||
| 144 | $user = \OC::$server->get(IUserSession::class)->getUser(); |
||
| 145 | if ($user) { |
||
| 146 | $userDisplayName = $user->getDisplayName(); |
||
| 147 | } |
||
| 148 | $this->assign('user_displayname', $userDisplayName); |
||
| 149 | $this->assign('user_uid', \OC_User::getUser()); |
||
| 150 | |||
| 151 | if ($user === null) { |
||
| 152 | $this->assign('userAvatarSet', false); |
||
| 153 | $this->assign('userStatus', false); |
||
| 154 | } else { |
||
| 155 | $this->assign('userAvatarSet', true); |
||
| 156 | $this->assign('userAvatarVersion', $this->config->getUserValue(\OC_User::getUser(), 'avatar', 'version', 0)); |
||
| 157 | } |
||
| 158 | } elseif ($renderAs === TemplateResponse::RENDER_AS_ERROR) { |
||
| 159 | parent::__construct('core', 'layout.guest', '', false); |
||
| 160 | $this->assign('bodyid', 'body-login'); |
||
| 161 | $this->assign('user_displayname', ''); |
||
| 162 | $this->assign('user_uid', ''); |
||
| 163 | } elseif ($renderAs === TemplateResponse::RENDER_AS_GUEST) { |
||
| 164 | parent::__construct('core', 'layout.guest'); |
||
| 165 | \OC_Util::addStyle('guest'); |
||
| 166 | $this->assign('bodyid', 'body-login'); |
||
| 167 | |||
| 168 | $userDisplayName = false; |
||
| 169 | $user = \OC::$server->get(IUserSession::class)->getUser(); |
||
| 170 | if ($user) { |
||
| 171 | $userDisplayName = $user->getDisplayName(); |
||
| 172 | } |
||
| 173 | $this->assign('user_displayname', $userDisplayName); |
||
| 174 | $this->assign('user_uid', \OC_User::getUser()); |
||
| 175 | } elseif ($renderAs === TemplateResponse::RENDER_AS_PUBLIC) { |
||
| 176 | parent::__construct('core', 'layout.public'); |
||
| 177 | $this->assign('appid', $appId); |
||
| 178 | $this->assign('bodyid', 'body-public'); |
||
| 179 | |||
| 180 | /** @var IRegistry $subscription */ |
||
| 181 | $subscription = \OC::$server->query(IRegistry::class); |
||
| 182 | $showSimpleSignup = $this->config->getSystemValueBool('simpleSignUpLink.shown', true); |
||
| 183 | if ($showSimpleSignup && $subscription->delegateHasValidSubscription()) { |
||
| 184 | $showSimpleSignup = false; |
||
| 185 | } |
||
| 186 | $this->assign('showSimpleSignUpLink', $showSimpleSignup); |
||
| 187 | } else { |
||
| 188 | parent::__construct('core', 'layout.base'); |
||
| 189 | } |
||
| 190 | // Send the language and the locale to our layouts |
||
| 191 | $lang = \OC::$server->getL10NFactory()->findLanguage(); |
||
| 192 | $locale = \OC::$server->getL10NFactory()->findLocale($lang); |
||
| 193 | |||
| 194 | $lang = str_replace('_', '-', $lang); |
||
| 195 | $this->assign('language', $lang); |
||
| 196 | $this->assign('locale', $locale); |
||
| 197 | |||
| 198 | if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
||
| 199 | if (empty(self::$versionHash)) { |
||
| 200 | $v = \OC_App::getAppVersions(); |
||
| 201 | $v['core'] = implode('.', \OCP\Util::getVersion()); |
||
| 202 | self::$versionHash = substr(md5(implode(',', $v)), 0, 8); |
||
| 203 | } |
||
| 204 | } else { |
||
| 205 | self::$versionHash = md5('not installed'); |
||
| 206 | } |
||
| 207 | |||
| 208 | // Add the js files |
||
| 209 | // TODO: remove deprecated OC_Util injection |
||
| 210 | $jsFiles = self::findJavascriptFiles(array_merge(\OC_Util::$scripts, Util::getScripts())); |
||
| 211 | $this->assign('jsfiles', []); |
||
| 212 | if ($this->config->getSystemValue('installed', false) && $renderAs != TemplateResponse::RENDER_AS_ERROR) { |
||
| 213 | // this is on purpose outside of the if statement below so that the initial state is prefilled (done in the getConfig() call) |
||
| 214 | // see https://github.com/nextcloud/server/pull/22636 for details |
||
| 215 | $jsConfigHelper = new JSConfigHelper( |
||
| 216 | \OC::$server->getL10N('lib'), |
||
| 217 | \OC::$server->query(Defaults::class), |
||
| 218 | \OC::$server->getAppManager(), |
||
| 219 | \OC::$server->getSession(), |
||
| 220 | \OC::$server->getUserSession()->getUser(), |
||
| 221 | $this->config, |
||
| 222 | \OC::$server->getGroupManager(), |
||
| 223 | \OC::$server->get(IniGetWrapper::class), |
||
| 224 | \OC::$server->getURLGenerator(), |
||
| 225 | \OC::$server->getCapabilitiesManager(), |
||
| 226 | \OC::$server->query(IInitialStateService::class) |
||
| 227 | ); |
||
| 228 | $config = $jsConfigHelper->getConfig(); |
||
| 229 | if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) { |
||
| 230 | $this->assign('inline_ocjs', $config); |
||
| 231 | } else { |
||
| 232 | $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash])); |
||
| 233 | } |
||
| 234 | } |
||
| 235 | foreach ($jsFiles as $info) { |
||
| 236 | $web = $info[1]; |
||
| 237 | $file = $info[2]; |
||
| 238 | $this->append('jsfiles', $web.'/'.$file . $this->getVersionHashSuffix()); |
||
| 239 | } |
||
| 240 | |||
| 241 | try { |
||
| 242 | $pathInfo = \OC::$server->getRequest()->getPathInfo(); |
||
| 243 | } catch (\Exception $e) { |
||
| 244 | $pathInfo = ''; |
||
| 245 | } |
||
| 246 | |||
| 247 | // Do not initialise scss appdata until we have a fully installed instance |
||
| 248 | // Do not load scss for update, errors, installation or login page |
||
| 249 | if (\OC::$server->getSystemConfig()->getValue('installed', false) |
||
| 250 | && !\OCP\Util::needUpgrade() |
||
| 251 | && $pathInfo !== '' |
||
| 252 | && !preg_match('/^\/login/', $pathInfo) |
||
| 253 | && $renderAs !== TemplateResponse::RENDER_AS_ERROR |
||
| 254 | ) { |
||
| 255 | $cssFiles = self::findStylesheetFiles(\OC_Util::$styles); |
||
| 256 | } else { |
||
| 257 | // If we ignore the scss compiler, |
||
| 258 | // we need to load the guest css fallback |
||
| 259 | \OC_Util::addStyle('guest'); |
||
| 260 | $cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false); |
||
| 261 | } |
||
| 262 | |||
| 263 | $this->assign('cssfiles', []); |
||
| 264 | $this->assign('printcssfiles', []); |
||
| 265 | $this->assign('versionHash', self::$versionHash); |
||
| 266 | foreach ($cssFiles as $info) { |
||
| 267 | $web = $info[1]; |
||
| 268 | $file = $info[2]; |
||
| 269 | |||
| 270 | if (substr($file, -strlen('print.css')) === 'print.css') { |
||
| 271 | $this->append('printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix()); |
||
| 272 | } else { |
||
| 273 | $suffix = $this->getVersionHashSuffix($web, $file); |
||
| 274 | |||
| 275 | if (strpos($file, '?v=') == false) { |
||
| 276 | $this->append('cssfiles', $web.'/'.$file . $suffix); |
||
| 277 | } else { |
||
| 278 | $this->append('cssfiles', $web.'/'.$file . '-' . substr($suffix, 3)); |
||
| 279 | } |
||
| 280 | } |
||
| 281 | } |
||
| 282 | |||
| 283 | $this->assign('initialStates', $this->initialState->getInitialStates()); |
||
| 284 | } |
||
| 401 |