Conditions | 21 |
Paths | 1998 |
Total Lines | 113 |
Code Lines | 78 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 462 |
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 |
||
64 | public function __construct( $renderAs, $appId = '' ) { |
||
65 | |||
66 | // yes - should be injected .... |
||
67 | $this->config = \OC::$server->getConfig(); |
||
68 | |||
69 | // Decide which page we show |
||
70 | if($renderAs == 'user') { |
||
71 | parent::__construct( 'core', 'layout.user' ); |
||
72 | if(in_array(OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) { |
||
73 | $this->assign('bodyid', 'body-settings'); |
||
74 | }else{ |
||
75 | $this->assign('bodyid', 'body-user'); |
||
76 | } |
||
77 | |||
78 | // Update notification |
||
79 | if($this->config->getSystemValue('updatechecker', true) === true && |
||
80 | OC_User::isAdminUser(OC_User::getUser())) { |
||
81 | $updater = new \OC\Updater(\OC::$server->getHTTPHelper(), |
||
82 | \OC::$server->getConfig(), \OC::$server->getLogger()); |
||
83 | $data = $updater->check(); |
||
84 | |||
85 | if(isset($data['version']) && $data['version'] != '' and $data['version'] !== Array()) { |
||
86 | $this->assign('updateAvailable', true); |
||
87 | $this->assign('updateVersion', $data['versionstring']); |
||
88 | $this->assign('updateLink', $data['web']); |
||
89 | \OCP\Util::addScript('core', 'update-notification'); |
||
90 | } else { |
||
91 | $this->assign('updateAvailable', false); // No update available or not an admin user |
||
92 | } |
||
93 | } else { |
||
94 | $this->assign('updateAvailable', false); // Update check is disabled |
||
95 | } |
||
96 | |||
97 | // Add navigation entry |
||
98 | |||
99 | $this->assign( 'application', ''); |
||
100 | $this->assign( 'appid', $appId ); |
||
101 | $navigation = OC_App::getNavigation(); |
||
102 | $this->assign( 'navigation', $navigation); |
||
103 | $settingsNavigation = OC_App::getSettingsNavigation(); |
||
104 | $this->assign( 'settingsnavigation', $settingsNavigation); |
||
105 | foreach($navigation as $entry) { |
||
106 | if ($entry['active']) { |
||
107 | $this->assign( 'application', $entry['name'] ); |
||
108 | break; |
||
109 | } |
||
110 | } |
||
111 | |||
112 | foreach($settingsNavigation as $entry) { |
||
113 | if ($entry['active']) { |
||
114 | $this->assign( 'application', $entry['name'] ); |
||
115 | break; |
||
116 | } |
||
117 | } |
||
118 | $userDisplayName = OC_User::getDisplayName(); |
||
119 | $appsMgmtActive = strpos(\OC::$server->getRequest()->getRequestUri(), \OC::$server->getURLGenerator()->linkToRoute('settings.AppSettings.viewApps')) === 0; |
||
120 | if ($appsMgmtActive) { |
||
121 | $l = \OC::$server->getL10N('lib'); |
||
122 | $this->assign('application', $l->t('Apps')); |
||
123 | } |
||
124 | $this->assign('user_displayname', $userDisplayName); |
||
125 | $this->assign('user_uid', OC_User::getUser()); |
||
126 | $this->assign('appsmanagement_active', $appsMgmtActive); |
||
127 | $this->assign('enableAvatars', $this->config->getSystemValue('enable_avatars', true) === true); |
||
128 | $this->assign('userAvatarSet', \OC_Helper::userAvatarSet(OC_User::getUser())); |
||
129 | } else if ($renderAs == 'error') { |
||
130 | parent::__construct('core', 'layout.guest', '', false); |
||
131 | $this->assign('bodyid', 'body-login'); |
||
132 | } else if ($renderAs == 'guest') { |
||
133 | parent::__construct('core', 'layout.guest'); |
||
134 | $this->assign('bodyid', 'body-login'); |
||
135 | } else { |
||
136 | parent::__construct('core', 'layout.base'); |
||
137 | |||
138 | } |
||
139 | // Send the language to our layouts |
||
140 | $this->assign('language', OC_L10N::findLanguage()); |
||
141 | |||
142 | |||
143 | if(empty(self::$versionHash)) { |
||
144 | $v = OC_App::getAppVersions(); |
||
145 | $v['core'] = implode('.', \OC_Util::getVersion()); |
||
146 | self::$versionHash = md5(implode(',', $v)); |
||
147 | } |
||
148 | |||
149 | $useAssetPipeline = self::isAssetPipelineEnabled(); |
||
150 | if ($useAssetPipeline) { |
||
151 | $this->append( 'jsfiles', OC_Helper::linkToRoute('js_config', array('v' => self::$versionHash))); |
||
152 | $this->generateAssets(); |
||
153 | } else { |
||
154 | // Add the js files |
||
155 | $jsFiles = self::findJavascriptFiles(OC_Util::$scripts); |
||
156 | $this->assign('jsfiles', array()); |
||
157 | if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') { |
||
158 | $this->append( 'jsfiles', OC_Helper::linkToRoute('js_config', array('v' => self::$versionHash))); |
||
159 | } |
||
160 | foreach($jsFiles as $info) { |
||
161 | $web = $info[1]; |
||
162 | $file = $info[2]; |
||
163 | $this->append( 'jsfiles', $web.'/'.$file . '?v=' . self::$versionHash); |
||
164 | } |
||
165 | |||
166 | // Add the css files |
||
167 | $cssFiles = self::findStylesheetFiles(OC_Util::$styles); |
||
168 | $this->assign('cssfiles', array()); |
||
169 | foreach($cssFiles as $info) { |
||
170 | $web = $info[1]; |
||
171 | $file = $info[2]; |
||
172 | |||
173 | $this->append( 'cssfiles', $web.'/'.$file . '?v=' . self::$versionHash); |
||
174 | } |
||
175 | } |
||
176 | } |
||
177 | |||
306 |