| Conditions | 26 |
| Paths | 16200 |
| Total Lines | 136 |
| Code Lines | 92 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 59 | public function __construct( $renderAs, $appId = '' ) { |
||
| 60 | |||
| 61 | // yes - should be injected .... |
||
| 62 | $this->config = \OC::$server->getConfig(); |
||
| 63 | |||
| 64 | |||
| 65 | // Decide which page we show |
||
| 66 | if($renderAs == 'user') { |
||
| 67 | parent::__construct( 'core', 'layout.user' ); |
||
| 68 | if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) { |
||
| 69 | $this->assign('bodyid', 'body-settings'); |
||
| 70 | }else{ |
||
| 71 | $this->assign('bodyid', 'body-user'); |
||
| 72 | } |
||
| 73 | |||
| 74 | // Code integrity notification |
||
| 75 | $integrityChecker = \OC::$server->getIntegrityCodeChecker(); |
||
| 76 | if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) { |
||
| 77 | \OCP\Util::addScript('core', 'integritycheck-failed-notification'); |
||
| 78 | } |
||
| 79 | |||
| 80 | // Add navigation entry |
||
| 81 | $this->assign( 'application', ''); |
||
| 82 | $this->assign( 'appid', $appId ); |
||
| 83 | $navigation = \OC_App::getNavigation(); |
||
| 84 | $this->assign( 'navigation', $navigation); |
||
| 85 | $settingsNavigation = \OC_App::getSettingsNavigation(); |
||
| 86 | $this->assign( 'settingsnavigation', $settingsNavigation); |
||
| 87 | foreach($navigation as $entry) { |
||
| 88 | if ($entry['active']) { |
||
| 89 | $this->assign( 'application', $entry['name'] ); |
||
| 90 | break; |
||
| 91 | } |
||
| 92 | } |
||
| 93 | |||
| 94 | foreach($settingsNavigation as $entry) { |
||
| 95 | if ($entry['active']) { |
||
| 96 | $this->assign( 'application', $entry['name'] ); |
||
| 97 | break; |
||
| 98 | } |
||
| 99 | } |
||
| 100 | $userDisplayName = \OC_User::getDisplayName(); |
||
| 101 | $this->assign('user_displayname', $userDisplayName); |
||
| 102 | $this->assign('user_uid', \OC_User::getUser()); |
||
| 103 | |||
| 104 | if (\OC_User::getUser() === false) { |
||
| 105 | $this->assign('userAvatarSet', false); |
||
| 106 | } else { |
||
| 107 | $this->assign('userAvatarSet', \OC::$server->getAvatarManager()->getAvatar(\OC_User::getUser())->exists()); |
||
| 108 | $this->assign('userAvatarVersion', $this->config->getUserValue(\OC_User::getUser(), 'avatar', 'version', 0)); |
||
| 109 | } |
||
| 110 | |||
| 111 | } else if ($renderAs == 'error') { |
||
| 112 | parent::__construct('core', 'layout.guest', '', false); |
||
| 113 | $this->assign('bodyid', 'body-login'); |
||
| 114 | } else if ($renderAs == 'guest') { |
||
| 115 | parent::__construct('core', 'layout.guest'); |
||
| 116 | $this->assign('bodyid', 'body-login'); |
||
| 117 | } else { |
||
| 118 | parent::__construct('core', 'layout.base'); |
||
| 119 | |||
| 120 | } |
||
| 121 | // Send the language to our layouts |
||
| 122 | $this->assign('language', \OC::$server->getL10NFactory()->findLanguage()); |
||
| 123 | |||
| 124 | if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
||
| 125 | if (empty(self::$versionHash)) { |
||
| 126 | $v = \OC_App::getAppVersions(); |
||
| 127 | $v['core'] = implode('.', \OCP\Util::getVersion()); |
||
| 128 | self::$versionHash = substr(md5(implode(',', $v)), 0, 8); |
||
| 129 | } |
||
| 130 | } else { |
||
| 131 | self::$versionHash = md5('not installed'); |
||
| 132 | } |
||
| 133 | |||
| 134 | // Add the js files |
||
| 135 | $jsFiles = self::findJavascriptFiles(\OC_Util::$scripts); |
||
| 136 | $this->assign('jsfiles', array()); |
||
| 137 | if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') { |
||
| 138 | if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) { |
||
| 139 | $jsConfigHelper = new JSConfigHelper( |
||
| 140 | \OC::$server->getL10N('core'), |
||
| 141 | \OC::$server->query(Defaults::class), |
||
| 142 | \OC::$server->getAppManager(), |
||
| 143 | \OC::$server->getSession(), |
||
| 144 | \OC::$server->getUserSession()->getUser(), |
||
| 145 | $this->config, |
||
| 146 | \OC::$server->getGroupManager(), |
||
| 147 | \OC::$server->getIniWrapper(), |
||
| 148 | \OC::$server->getURLGenerator() |
||
| 149 | ); |
||
| 150 | $this->assign('inline_ocjs', $jsConfigHelper->getConfig()); |
||
| 151 | } else { |
||
| 152 | $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash])); |
||
| 153 | } |
||
| 154 | } |
||
| 155 | foreach($jsFiles as $info) { |
||
| 156 | $web = $info[1]; |
||
| 157 | $file = $info[2]; |
||
| 158 | $this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
||
| 159 | } |
||
| 160 | |||
| 161 | try { |
||
| 162 | $pathInfo = \OC::$server->getRequest()->getPathInfo(); |
||
| 163 | } catch (\Exception $e) { |
||
| 164 | $pathInfo = ''; |
||
| 165 | } |
||
| 166 | |||
| 167 | // Do not initialise scss appdata until we have a fully installed instance |
||
| 168 | // Do not load scss for update, errors, installation or login page |
||
| 169 | if(\OC::$server->getSystemConfig()->getValue('installed', false) |
||
| 170 | && !\OCP\Util::needUpgrade() |
||
| 171 | && $pathInfo !== '' |
||
| 172 | && !preg_match('/^\/login/', $pathInfo)) { |
||
| 173 | $cssFiles = self::findStylesheetFiles(\OC_Util::$styles); |
||
| 174 | } else { |
||
| 175 | // If we ignore the scss compiler, |
||
| 176 | // we need to load the guest css fallback |
||
| 177 | \OC_Util::addStyle('guest'); |
||
| 178 | $cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false); |
||
| 179 | } |
||
| 180 | |||
| 181 | $this->assign('cssfiles', array()); |
||
| 182 | $this->assign('printcssfiles', []); |
||
| 183 | $this->assign('versionHash', self::$versionHash); |
||
| 184 | foreach($cssFiles as $info) { |
||
| 185 | $web = $info[1]; |
||
| 186 | $file = $info[2]; |
||
| 187 | |||
| 188 | if (substr($file, -strlen('print.css')) === 'print.css') { |
||
| 189 | $this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
||
| 190 | } else { |
||
| 191 | $this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix($web, $file) ); |
||
| 192 | } |
||
| 193 | } |
||
| 194 | } |
||
| 195 | |||
| 318 |