| Conditions | 33 |
| Paths | 253 |
| Total Lines | 67 |
| Code Lines | 51 |
| Lines | 16 |
| Ratio | 23.88 % |
| 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 |
||
| 152 | public function imagePath(string $app, string $image): string { |
||
| 153 | $cache = $this->cacheFactory->createDistributed('imagePath-'.md5($this->getBaseUrl()).'-'); |
||
| 154 | $cacheKey = $app.'-'.$image; |
||
| 155 | if($key = $cache->get($cacheKey)) { |
||
| 156 | return $key; |
||
| 157 | } |
||
| 158 | |||
| 159 | // Read the selected theme from the config file |
||
| 160 | $theme = \OC_Util::getTheme(); |
||
| 161 | |||
| 162 | //if a theme has a png but not an svg always use the png |
||
| 163 | $basename = substr(basename($image),0,-4); |
||
| 164 | |||
| 165 | $appPath = \OC_App::getAppPath($app); |
||
| 166 | |||
| 167 | // Check if the app is in the app folder |
||
| 168 | $path = ''; |
||
| 169 | $themingEnabled = $this->config->getSystemValue('installed', false) && \OCP\App::isEnabled('theming') && \OC_App::isAppLoaded('theming'); |
||
| 170 | $themingImagePath = false; |
||
| 171 | if($themingEnabled) { |
||
| 172 | $themingDefaults = \OC::$server->getThemingDefaults(); |
||
| 173 | if ($themingDefaults instanceof ThemingDefaults) { |
||
| 174 | $themingImagePath = $themingDefaults->replaceImagePath($app, $image); |
||
| 175 | } |
||
| 176 | } |
||
| 177 | |||
| 178 | if (file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$image")) { |
||
| 179 | $path = \OC::$WEBROOT . "/themes/$theme/apps/$app/img/$image"; |
||
| 180 | } elseif (!file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$basename.svg") |
||
| 181 | && file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$basename.png")) { |
||
| 182 | $path = \OC::$WEBROOT . "/themes/$theme/apps/$app/img/$basename.png"; |
||
| 183 | } elseif (!empty($app) and file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$image")) { |
||
| 184 | $path = \OC::$WEBROOT . "/themes/$theme/$app/img/$image"; |
||
| 185 | View Code Duplication | } elseif (!empty($app) and (!file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$basename.svg") |
|
| 186 | && file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$basename.png"))) { |
||
| 187 | $path = \OC::$WEBROOT . "/themes/$theme/$app/img/$basename.png"; |
||
| 188 | } elseif (file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$image")) { |
||
| 189 | $path = \OC::$WEBROOT . "/themes/$theme/core/img/$image"; |
||
| 190 | View Code Duplication | } elseif (!file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$basename.svg") |
|
| 191 | && file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$basename.png")) { |
||
| 192 | $path = \OC::$WEBROOT . "/themes/$theme/core/img/$basename.png"; |
||
| 193 | } elseif($themingEnabled && $themingImagePath) { |
||
| 194 | $path = $themingImagePath; |
||
| 195 | } elseif ($appPath && file_exists($appPath . "/img/$image")) { |
||
| 196 | $path = \OC_App::getAppWebPath($app) . "/img/$image"; |
||
| 197 | } elseif ($appPath && !file_exists($appPath . "/img/$basename.svg") |
||
| 198 | && file_exists($appPath . "/img/$basename.png")) { |
||
| 199 | $path = \OC_App::getAppWebPath($app) . "/img/$basename.png"; |
||
| 200 | } elseif (!empty($app) and file_exists(\OC::$SERVERROOT . "/$app/img/$image")) { |
||
| 201 | $path = \OC::$WEBROOT . "/$app/img/$image"; |
||
| 202 | View Code Duplication | } elseif (!empty($app) and (!file_exists(\OC::$SERVERROOT . "/$app/img/$basename.svg") |
|
| 203 | && file_exists(\OC::$SERVERROOT . "/$app/img/$basename.png"))) { |
||
| 204 | $path = \OC::$WEBROOT . "/$app/img/$basename.png"; |
||
| 205 | } elseif (file_exists(\OC::$SERVERROOT . "/core/img/$image")) { |
||
| 206 | $path = \OC::$WEBROOT . "/core/img/$image"; |
||
| 207 | View Code Duplication | } elseif (!file_exists(\OC::$SERVERROOT . "/core/img/$basename.svg") |
|
| 208 | && file_exists(\OC::$SERVERROOT . "/core/img/$basename.png")) { |
||
| 209 | $path = \OC::$WEBROOT . "/themes/$theme/core/img/$basename.png"; |
||
| 210 | } |
||
| 211 | |||
| 212 | if($path !== '') { |
||
| 213 | $cache->set($cacheKey, $path); |
||
| 214 | return $path; |
||
| 215 | } |
||
| 216 | |||
| 217 | throw new RuntimeException('image not found: image:' . $image . ' webroot:' . \OC::$WEBROOT . ' serverroot:' . \OC::$SERVERROOT); |
||
| 218 | } |
||
| 219 | |||
| 256 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: