| Conditions | 22 |
| Paths | 1557 |
| Total Lines | 79 |
| Code Lines | 50 |
| 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 | // either a route or a static page must be defined |
||
| 145 | if (!isset($nav['route']) && !isset($nav['static'])) { |
||
| 146 | continue; |
||
| 147 | } |
||
| 148 | |||
| 149 | $role = isset($nav['@attributes']['role']) ? $nav['@attributes']['role'] : 'all'; |
||
| 150 | /** |
||
| 151 | * Can have multiple roles like role="admin,sub-admin" |
||
| 152 | */ |
||
| 153 | $role = explode(',', $role); |
||
| 154 | //Remove whitespace in the role elements |
||
| 155 | $role = array_map('trim', $role); |
||
| 156 | |||
| 157 | $shallContinue = false; |
||
| 158 | if ($this->isAdmin() && (in_array('admin', $role, true) === true)) { |
||
| 159 | $shallContinue = true; |
||
| 160 | } |
||
| 161 | if ($this->isSubAdmin() && (in_array('sub-admin', $role, true) === true)) { |
||
| 162 | $shallContinue = true; |
||
| 163 | } |
||
| 164 | if (in_array('all', $role, true) === true) { |
||
| 165 | $shallContinue = true; |
||
| 166 | } |
||
| 167 | |||
| 168 | if ($shallContinue === false) { |
||
| 169 | continue; |
||
| 170 | } |
||
| 171 | |||
| 172 | $l = $this->l10nFac->get($app); |
||
| 173 | $order = isset($nav['order']) ? $nav['order'] : 100; |
||
| 174 | if (isset($nav['route'])) { |
||
| 175 | $route = $this->urlGenerator->linkToRoute($nav['route']); |
||
| 176 | } else { |
||
| 177 | $html = 'index.html'; |
||
| 178 | if (isset($nav['static'])) { |
||
| 179 | $html = $nav['static']; |
||
| 180 | } |
||
| 181 | $route = $this->urlGenerator->linkTo($app, $html); |
||
| 182 | } |
||
| 183 | $name = isset($nav['name']) ? $nav['name'] : ucfirst($app); |
||
| 184 | $icon = isset($nav['icon']) ? $nav['icon'] : 'app.svg'; |
||
| 185 | $iconPath = null; |
||
| 186 | foreach ([$icon, "$app.svg"] as $i) { |
||
| 187 | try { |
||
| 188 | $iconPath = $this->urlGenerator->imagePath($app, $i); |
||
| 189 | break; |
||
| 190 | } catch (\RuntimeException $ex) { |
||
| 191 | // no icon? - ignore it then |
||
| 192 | } |
||
| 193 | } |
||
| 194 | |||
| 195 | if ($iconPath === null) { |
||
| 196 | $iconPath = $this->urlGenerator->imagePath('core', 'default-app-icon.svg'); |
||
| 197 | } |
||
| 198 | |||
| 199 | $this->add([ |
||
| 200 | 'id' => $app, |
||
| 201 | 'order' => $order, |
||
| 202 | 'href' => $route, |
||
| 203 | 'icon' => $iconPath, |
||
| 204 | 'name' => $l->t($name), |
||
| 205 | ]); |
||
| 206 | } |
||
| 207 | } |
||
| 208 | |||
| 226 |