| Conditions | 17 |
| Paths | 73 |
| Total Lines | 53 |
| Code Lines | 37 |
| 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 |
||
| 129 | private function init() { |
||
| 130 | if ($this->init) { |
||
| 131 | return; |
||
| 132 | } |
||
| 133 | $this->init = true; |
||
| 134 | if ($this->appManager === null) { |
||
| 135 | return; |
||
| 136 | } |
||
| 137 | foreach ($this->appManager->getInstalledApps() as $app) { |
||
| 138 | // load plugins and collections from info.xml |
||
| 139 | $info = $this->appManager->getAppInfo($app); |
||
| 140 | if (!isset($info['navigation'])) { |
||
| 141 | continue; |
||
| 142 | } |
||
| 143 | $nav = $info['navigation']; |
||
| 144 | if (!isset($nav['route'])) { |
||
| 145 | continue; |
||
| 146 | } |
||
| 147 | $role = isset($nav['@attributes']['role']) ? $nav['@attributes']['role'] : 'all'; |
||
| 148 | if ($role === 'admin' && !$this->isAdmin()) { |
||
| 149 | continue; |
||
| 150 | } |
||
| 151 | if ($role === 'sub-admin' && !$this->isSubAdmin()) { |
||
| 152 | continue; |
||
| 153 | } |
||
| 154 | $l = $this->l10nFac->get($app); |
||
| 155 | $order = isset($nav['order']) ? $nav['order'] : 100; |
||
| 156 | $route = $this->urlGenerator->linkToRoute($nav['route']); |
||
| 157 | $name = isset($nav['name']) ? $nav['name'] : ucfirst($app); |
||
| 158 | $icon = isset($nav['icon']) ? $nav['icon'] : 'app.svg'; |
||
| 159 | $iconPath = null; |
||
| 160 | foreach ([$icon, "$app.svg"] as $i) { |
||
| 161 | try { |
||
| 162 | $iconPath = $this->urlGenerator->imagePath($app, $i); |
||
| 163 | break; |
||
| 164 | } catch (\RuntimeException $ex) { |
||
| 165 | // no icon? - ignore it then |
||
| 166 | } |
||
| 167 | } |
||
| 168 | |||
| 169 | if ($iconPath === null) { |
||
| 170 | $iconPath = $this->urlGenerator->imagePath('core', 'default-app-icon.svg'); |
||
| 171 | } |
||
| 172 | |||
| 173 | $this->add([ |
||
| 174 | 'id' => $app, |
||
| 175 | 'order' => $order, |
||
| 176 | 'href' => $route, |
||
| 177 | 'icon' => $iconPath, |
||
| 178 | 'name' => $l->t($name), |
||
| 179 | ]); |
||
| 180 | } |
||
| 181 | } |
||
| 182 | |||
| 200 |