| Conditions | 23 |
| Paths | 15876 |
| Total Lines | 134 |
| Code Lines | 94 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| 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 |
||
| 54 | public function __construct( $renderAs, $appId = '' ) { |
||
| 55 | |||
| 56 | // yes - should be injected .... |
||
| 57 | $this->config = \OC::$server->getConfig(); |
||
| 58 | |||
| 59 | // Decide which page we show |
||
| 60 | if($renderAs == 'user') { |
||
| 61 | parent::__construct( 'core', 'layout.user' ); |
||
| 62 | if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) { |
||
| 63 | $this->assign('bodyid', 'body-settings'); |
||
| 64 | }else{ |
||
| 65 | $this->assign('bodyid', 'body-user'); |
||
| 66 | } |
||
| 67 | |||
| 68 | // Code integrity notification |
||
| 69 | $integrityChecker = \OC::$server->getIntegrityCodeChecker(); |
||
| 70 | if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) { |
||
| 71 | \OCP\Util::addScript('core', 'integritycheck-failed-notification'); |
||
| 72 | } |
||
| 73 | |||
| 74 | // Add navigation entry |
||
| 75 | $this->assign( 'application', ''); |
||
| 76 | $this->assign( 'appid', $appId ); |
||
| 77 | $navigation = \OC_App::getNavigation(); |
||
| 78 | $this->assign( 'navigation', $navigation); |
||
| 79 | $settingsNavigation = \OC_App::getSettingsNavigation(); |
||
| 80 | $this->assign( 'settingsnavigation', $settingsNavigation); |
||
| 81 | foreach($navigation as $entry) { |
||
| 82 | if ($entry['active']) { |
||
| 83 | $this->assign( 'application', $entry['name'] ); |
||
| 84 | break; |
||
| 85 | } |
||
| 86 | } |
||
| 87 | |||
| 88 | foreach($settingsNavigation as $entry) { |
||
| 89 | if ($entry['active']) { |
||
| 90 | $this->assign( 'application', $entry['name'] ); |
||
| 91 | break; |
||
| 92 | } |
||
| 93 | } |
||
| 94 | $userDisplayName = \OC_User::getDisplayName(); |
||
| 95 | $appsMgmtActive = strpos(\OC::$server->getRequest()->getRequestUri(), \OC::$server->getURLGenerator()->linkToRoute('settings.AppSettings.viewApps')) === 0; |
||
| 96 | if ($appsMgmtActive) { |
||
| 97 | $l = \OC::$server->getL10N('lib'); |
||
| 98 | $this->assign('application', $l->t('Apps')); |
||
| 99 | } |
||
| 100 | $this->assign('user_displayname', $userDisplayName); |
||
| 101 | $this->assign('user_uid', \OC_User::getUser()); |
||
| 102 | $this->assign('appsmanagement_active', $appsMgmtActive); |
||
| 103 | $this->assign('enableAvatars', $this->config->getSystemValue('enable_avatars', true) === true); |
||
| 104 | |||
| 105 | if (\OC_User::getUser() === false) { |
||
| 106 | $this->assign('userAvatarSet', false); |
||
| 107 | } else { |
||
| 108 | $this->assign('userAvatarSet', \OC::$server->getAvatarManager()->getAvatar(\OC_User::getUser())->exists()); |
||
| 109 | $this->assign('userAvatarVersion', \OC::$server->getConfig()->getUserValue(\OC_User::getUser(), 'avatar', 'version', 0)); |
||
| 110 | } |
||
| 111 | |||
| 112 | } else if ($renderAs == 'error') { |
||
| 113 | parent::__construct('core', 'layout.guest', '', false); |
||
| 114 | $this->assign('bodyid', 'body-login'); |
||
| 115 | } else if ($renderAs == 'guest') { |
||
| 116 | parent::__construct('core', 'layout.guest'); |
||
| 117 | $this->assign('bodyid', 'body-login'); |
||
| 118 | } else { |
||
| 119 | parent::__construct('core', 'layout.base'); |
||
| 120 | |||
| 121 | } |
||
| 122 | // Send the language to our layouts |
||
| 123 | $this->assign('language', \OC::$server->getL10NFactory()->findLanguage()); |
||
| 124 | |||
| 125 | if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
||
| 126 | if (empty(self::$versionHash)) { |
||
| 127 | $v = \OC_App::getAppVersions(); |
||
| 128 | $v['core'] = implode('.', \OCP\Util::getVersion()); |
||
| 129 | self::$versionHash = md5(implode(',', $v)); |
||
| 130 | } |
||
| 131 | } else { |
||
| 132 | self::$versionHash = md5('not installed'); |
||
| 133 | } |
||
| 134 | |||
| 135 | // Add the js files |
||
| 136 | $jsFiles = self::findJavascriptFiles(\OC_Util::$scripts); |
||
| 137 | $this->assign('jsfiles', array()); |
||
| 138 | if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') { |
||
| 139 | if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) { |
||
| 140 | $jsConfigHelper = new JSConfigHelper( |
||
| 141 | \OC::$server->getL10N('core'), |
||
| 142 | \OC::$server->getThemingDefaults(), |
||
| 143 | \OC::$server->getAppManager(), |
||
| 144 | \OC::$server->getSession(), |
||
| 145 | \OC::$server->getUserSession()->getUser(), |
||
| 146 | \OC::$server->getConfig(), |
||
| 147 | \OC::$server->getGroupManager(), |
||
| 148 | \OC::$server->getIniWrapper(), |
||
| 149 | \OC::$server->getURLGenerator() |
||
| 150 | ); |
||
| 151 | $this->assign('inline_ocjs', $jsConfigHelper->getConfig()); |
||
| 152 | $this->assign('foo', 'bar'); |
||
| 153 | } else { |
||
| 154 | $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash])); |
||
| 155 | } |
||
| 156 | } |
||
| 157 | foreach($jsFiles as $info) { |
||
| 158 | $web = $info[1]; |
||
| 159 | $file = $info[2]; |
||
| 160 | $this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
||
| 161 | } |
||
| 162 | |||
| 163 | // Add the css files and check if server is already installed to prevent |
||
| 164 | // appdata initialisation before database configuration |
||
| 165 | if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
||
| 166 | $cssFiles = self::findStylesheetFiles(\OC_Util::$styles); |
||
| 167 | } else { |
||
| 168 | $cssFiles = array( |
||
| 169 | [\OC::$SERVERROOT, \OC::$WEBROOT, 'core/css/global.css'], |
||
| 170 | [\OC::$SERVERROOT, \OC::$WEBROOT, 'core/css/fonts.css'], |
||
| 171 | [\OC::$SERVERROOT, \OC::$WEBROOT, 'core/css/installation.css'] |
||
| 172 | ); |
||
| 173 | } |
||
| 174 | $this->assign('cssfiles', array()); |
||
| 175 | $this->assign('printcssfiles', []); |
||
| 176 | $this->assign('versionHash', self::$versionHash); |
||
| 177 | foreach($cssFiles as $info) { |
||
| 178 | $web = $info[1]; |
||
| 179 | $file = $info[2]; |
||
| 180 | |||
| 181 | if (substr($file, -strlen('print.css')) === 'print.css') { |
||
| 182 | $this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
||
| 183 | } else { |
||
| 184 | $this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
||
| 185 | } |
||
| 186 | } |
||
| 187 | } |
||
| 188 | |||
| 255 |