| Conditions | 27 |
| Paths | 163 |
| Total Lines | 123 |
| Code Lines | 85 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 185 | private function init() { |
||
| 186 | if ($this->init) { |
||
| 187 | return; |
||
| 188 | } |
||
| 189 | $this->init = true; |
||
| 190 | |||
| 191 | $l = $this->l10nFac->get('lib'); |
||
| 192 | if ($this->config->getSystemValue('knowledgebaseenabled', true)) { |
||
| 193 | $this->add([ |
||
| 194 | 'type' => 'settings', |
||
| 195 | 'id' => 'help', |
||
| 196 | 'order' => 6, |
||
| 197 | 'href' => $this->urlGenerator->linkToRoute('settings.Help.help'), |
||
| 198 | 'name' => $l->t('Help'), |
||
| 199 | 'icon' => $this->urlGenerator->imagePath('settings', 'help.svg'), |
||
| 200 | ]); |
||
| 201 | } |
||
| 202 | |||
| 203 | if ($this->userSession->isLoggedIn()) { |
||
| 204 | if ($this->isAdmin()) { |
||
| 205 | // App management |
||
| 206 | $this->add([ |
||
| 207 | 'type' => 'settings', |
||
| 208 | 'id' => 'core_apps', |
||
| 209 | 'order' => 4, |
||
| 210 | 'href' => $this->urlGenerator->linkToRoute('settings.AppSettings.viewApps'), |
||
| 211 | 'icon' => $this->urlGenerator->imagePath('settings', 'apps.svg'), |
||
| 212 | 'name' => $l->t('Apps'), |
||
| 213 | ]); |
||
| 214 | } |
||
| 215 | |||
| 216 | // Personal and (if applicable) admin settings |
||
| 217 | $this->add([ |
||
| 218 | 'type' => 'settings', |
||
| 219 | 'id' => 'settings', |
||
| 220 | 'order' => 2, |
||
| 221 | 'href' => $this->urlGenerator->linkToRoute('settings.PersonalSettings.index'), |
||
| 222 | 'name' => $l->t('Settings'), |
||
| 223 | 'icon' => $this->urlGenerator->imagePath('settings', 'admin.svg'), |
||
| 224 | ]); |
||
| 225 | |||
| 226 | $logoutUrl = \OC_User::getLogoutUrl($this->urlGenerator); |
||
| 227 | if ($logoutUrl !== '') { |
||
| 228 | // Logout |
||
| 229 | $this->add([ |
||
| 230 | 'type' => 'settings', |
||
| 231 | 'id' => 'logout', |
||
| 232 | 'order' => 99999, |
||
| 233 | 'href' => $logoutUrl, |
||
| 234 | 'name' => $l->t('Log out'), |
||
| 235 | 'icon' => $this->urlGenerator->imagePath('core', 'actions/logout.svg'), |
||
| 236 | ]); |
||
| 237 | } |
||
| 238 | |||
| 239 | if ($this->isSubadmin()) { |
||
| 240 | // User management |
||
| 241 | $this->add([ |
||
| 242 | 'type' => 'settings', |
||
| 243 | 'id' => 'core_users', |
||
| 244 | 'order' => 5, |
||
| 245 | 'href' => $this->urlGenerator->linkToRoute('settings.Users.usersList'), |
||
| 246 | 'name' => $l->t('Users'), |
||
| 247 | 'icon' => $this->urlGenerator->imagePath('settings', 'users.svg'), |
||
| 248 | ]); |
||
| 249 | } |
||
| 250 | } |
||
| 251 | |||
| 252 | if ($this->appManager === 'null') { |
||
| 253 | return; |
||
| 254 | } |
||
| 255 | |||
| 256 | if ($this->userSession->isLoggedIn()) { |
||
| 257 | $apps = $this->appManager->getEnabledAppsForUser($this->userSession->getUser()); |
||
| 258 | } else { |
||
| 259 | $apps = $this->appManager->getInstalledApps(); |
||
| 260 | } |
||
| 261 | |||
| 262 | foreach ($apps as $app) { |
||
| 263 | if (!$this->userSession->isLoggedIn() && !$this->appManager->isEnabledForUser($app, $this->userSession->getUser())) { |
||
| 264 | continue; |
||
| 265 | } |
||
| 266 | |||
| 267 | // load plugins and collections from info.xml |
||
| 268 | $info = $this->appManager->getAppInfo($app); |
||
| 269 | if (!isset($info['navigations']['navigation'])) { |
||
| 270 | continue; |
||
| 271 | } |
||
| 272 | foreach ($info['navigations']['navigation'] as $key => $nav) { |
||
| 273 | if (!isset($nav['name'])) { |
||
| 274 | continue; |
||
| 275 | } |
||
| 276 | if (!isset($nav['route'])) { |
||
| 277 | continue; |
||
| 278 | } |
||
| 279 | $role = isset($nav['@attributes']['role']) ? $nav['@attributes']['role'] : 'all'; |
||
| 280 | if ($role === 'admin' && !$this->isAdmin()) { |
||
| 281 | continue; |
||
| 282 | } |
||
| 283 | $l = $this->l10nFac->get($app); |
||
| 284 | $id = $nav['id'] ?? $app . ($key === 0 ? '' : $key); |
||
| 285 | $order = isset($nav['order']) ? $nav['order'] : 100; |
||
| 286 | $type = isset($nav['type']) ? $nav['type'] : 'link'; |
||
| 287 | $route = $nav['route'] !== '' ? $this->urlGenerator->linkToRoute($nav['route']) : ''; |
||
| 288 | $icon = isset($nav['icon']) ? $nav['icon'] : 'app.svg'; |
||
| 289 | foreach ([$icon, "$app.svg"] as $i) { |
||
| 290 | try { |
||
| 291 | $icon = $this->urlGenerator->imagePath($app, $i); |
||
| 292 | break; |
||
| 293 | } catch (\RuntimeException $ex) { |
||
| 294 | // no icon? - ignore it then |
||
| 295 | } |
||
| 296 | } |
||
| 297 | if ($icon === null) { |
||
| 298 | $icon = $this->urlGenerator->imagePath('core', 'default-app-icon'); |
||
| 299 | } |
||
| 300 | |||
| 301 | $this->add([ |
||
| 302 | 'id' => $id, |
||
| 303 | 'order' => $order, |
||
| 304 | 'href' => $route, |
||
| 305 | 'icon' => $icon, |
||
| 306 | 'type' => $type, |
||
| 307 | 'name' => $l->t($nav['name']), |
||
| 308 | ]); |
||
| 333 |