| Conditions | 23 |
| Paths | 73 |
| Total Lines | 128 |
| Code Lines | 88 |
| Lines | 43 |
| Ratio | 33.59 % |
| 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 |
||
| 149 | private function init() { |
||
| 150 | if ($this->init) { |
||
| 151 | return; |
||
| 152 | } |
||
| 153 | $this->init = true; |
||
| 154 | |||
| 155 | $l = $this->l10nFac->get('lib'); |
||
| 156 | View Code Duplication | if ($this->config->getSystemValue('knowledgebaseenabled', true)) { |
|
| 157 | $this->add([ |
||
| 158 | 'type' => 'settings', |
||
| 159 | 'id' => 'help', |
||
| 160 | 'order' => 5, |
||
| 161 | 'href' => $this->urlGenerator->linkToRoute('settings_help'), |
||
| 162 | 'name' => $l->t('Help'), |
||
| 163 | 'icon' => $this->urlGenerator->imagePath('settings', 'help.svg'), |
||
| 164 | ]); |
||
| 165 | } |
||
| 166 | |||
| 167 | if ($this->userSession->isLoggedIn()) { |
||
| 168 | View Code Duplication | if ($this->isAdmin()) { |
|
| 169 | // App management |
||
| 170 | $this->add([ |
||
| 171 | 'type' => 'settings', |
||
| 172 | 'id' => 'core_apps', |
||
| 173 | 'order' => 3, |
||
| 174 | 'href' => $this->urlGenerator->linkToRoute('settings.AppSettings.viewApps'), |
||
| 175 | 'icon' => $this->urlGenerator->imagePath('settings', 'apps.svg'), |
||
| 176 | 'name' => $l->t('Apps'), |
||
| 177 | ]); |
||
| 178 | } |
||
| 179 | |||
| 180 | // Personal settings |
||
| 181 | $this->add([ |
||
| 182 | 'type' => 'settings', |
||
| 183 | 'id' => 'personal', |
||
| 184 | 'order' => 1, |
||
| 185 | 'href' => $this->urlGenerator->linkToRoute('settings_personal'), |
||
| 186 | 'name' => $l->t('Personal'), |
||
| 187 | 'icon' => $this->urlGenerator->imagePath('settings', 'personal.svg'), |
||
| 188 | ]); |
||
| 189 | |||
| 190 | // Logout |
||
| 191 | $this->add([ |
||
| 192 | 'type' => 'settings', |
||
| 193 | 'id' => 'logout', |
||
| 194 | 'order' => 99999, |
||
| 195 | 'href' => $this->urlGenerator->linkToRouteAbsolute( |
||
| 196 | 'core.login.logout', |
||
| 197 | ['requesttoken' => \OCP\Util::callRegister()] |
||
| 198 | ), |
||
| 199 | 'name' => $l->t('Log out'), |
||
| 200 | 'icon' => $this->urlGenerator->imagePath('core', 'actions/logout.svg'), |
||
| 201 | ]); |
||
| 202 | |||
| 203 | View Code Duplication | if ($this->isSubadmin()) { |
|
| 204 | // User management |
||
| 205 | $this->add([ |
||
| 206 | 'type' => 'settings', |
||
| 207 | 'id' => 'core_users', |
||
| 208 | 'order' => 4, |
||
| 209 | 'href' => $this->urlGenerator->linkToRoute('settings_users'), |
||
| 210 | 'name' => $l->t('Users'), |
||
| 211 | 'icon' => $this->urlGenerator->imagePath('settings', 'users.svg'), |
||
| 212 | ]); |
||
| 213 | } |
||
| 214 | |||
| 215 | View Code Duplication | if ($this->isAdmin()) { |
|
| 216 | // Admin settings |
||
| 217 | $this->add([ |
||
| 218 | 'type' => 'settings', |
||
| 219 | 'id' => 'admin', |
||
| 220 | 'order' => 2, |
||
| 221 | 'href' => $this->urlGenerator->linkToRoute('settings.AdminSettings.index'), |
||
| 222 | 'name' => $l->t('Admin'), |
||
| 223 | 'icon' => $this->urlGenerator->imagePath('settings', 'admin.svg'), |
||
| 224 | ]); |
||
| 225 | } |
||
| 226 | } |
||
| 227 | |||
| 228 | if ($this->appManager === 'null') { |
||
| 229 | return; |
||
| 230 | } |
||
| 231 | foreach ($this->appManager->getInstalledApps() as $app) { |
||
| 232 | // load plugins and collections from info.xml |
||
| 233 | $info = $this->appManager->getAppInfo($app); |
||
| 234 | if (empty($info['navigations'])) { |
||
| 235 | continue; |
||
| 236 | } |
||
| 237 | foreach ($info['navigations'] as $nav) { |
||
| 238 | if (!isset($nav['name'])) { |
||
| 239 | continue; |
||
| 240 | } |
||
| 241 | if (!isset($nav['route'])) { |
||
| 242 | continue; |
||
| 243 | } |
||
| 244 | $role = isset($nav['@attributes']['role']) ? $nav['@attributes']['role'] : 'all'; |
||
| 245 | if ($role === 'admin' && !$this->isAdmin()) { |
||
| 246 | continue; |
||
| 247 | } |
||
| 248 | $l = $this->l10nFac->get($app); |
||
| 249 | $id = isset($nav['id']) ? $nav['id'] : $app; |
||
| 250 | $order = isset($nav['order']) ? $nav['order'] : 100; |
||
| 251 | $type = isset($nav['type']) ? $nav['type'] : 'link'; |
||
| 252 | $route = $this->urlGenerator->linkToRoute($nav['route']); |
||
| 253 | $icon = isset($nav['icon']) ? $nav['icon'] : 'app.svg'; |
||
| 254 | foreach ([$icon, "$app.svg"] as $i) { |
||
| 255 | try { |
||
| 256 | $icon = $this->urlGenerator->imagePath($app, $i); |
||
| 257 | break; |
||
| 258 | } catch (\RuntimeException $ex) { |
||
| 259 | // no icon? - ignore it then |
||
| 260 | } |
||
| 261 | } |
||
| 262 | if ($icon === null) { |
||
| 263 | $icon = $this->urlGenerator->imagePath('core', 'default-app-icon'); |
||
| 264 | } |
||
| 265 | |||
| 266 | $this->add([ |
||
| 267 | 'id' => $id, |
||
| 268 | 'order' => $order, |
||
| 269 | 'href' => $route, |
||
| 270 | 'icon' => $icon, |
||
| 271 | 'type' => $type, |
||
| 272 | 'name' => $l->t($nav['name']), |
||
| 273 | ]); |
||
| 274 | } |
||
| 275 | } |
||
| 276 | } |
||
| 277 | |||
| 294 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.