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