| Conditions | 41 |
| Paths | 115 |
| Total Lines | 69 |
| Code Lines | 57 |
| Lines | 16 |
| Ratio | 23.19 % |
| 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 |
||
| 151 | public function imagePath($app, $image) { |
||
| 152 | $cache = $this->cacheFactory->create('imagePath-'.md5($this->getBaseUrl()).'-'); |
||
| 153 | $cacheKey = $app.'-'.$image; |
||
| 154 | if($key = $cache->get($cacheKey)) { |
||
| 155 | return $key; |
||
| 156 | } |
||
| 157 | |||
| 158 | // Read the selected theme from the config file |
||
| 159 | $theme = \OC_Util::getTheme(); |
||
| 160 | |||
| 161 | //if a theme has a png but not an svg always use the png |
||
| 162 | $basename = substr(basename($image),0,-4); |
||
| 163 | |||
| 164 | $appPath = \OC_App::getAppPath($app); |
||
| 165 | |||
| 166 | // Check if the app is in the app folder |
||
| 167 | $path = ''; |
||
| 168 | $themingEnabled = $this->config->getSystemValue('installed', false) && \OCP\App::isEnabled('theming') && \OC_App::isAppLoaded('theming'); |
||
| 169 | if($themingEnabled && $image === 'favicon.ico' && \OC::$server->getThemingDefaults()->shouldReplaceIcons()) { |
||
| 170 | $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
||
| 171 | if($app === '') { $app = 'core'; } |
||
| 172 | $path = $this->linkToRoute('theming.Icon.getFavicon', [ 'app' => $app ]) . '?v='. $cacheBusterValue; |
||
| 173 | } elseif($themingEnabled && $image === 'favicon-touch.png' && \OC::$server->getThemingDefaults()->shouldReplaceIcons()) { |
||
| 174 | $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
||
| 175 | if($app === '') { $app = 'core'; } |
||
| 176 | $path = $this->linkToRoute('theming.Icon.getTouchIcon', [ 'app' => $app ]) . '?v='. $cacheBusterValue; |
||
| 177 | } elseif($themingEnabled && $image === 'favicon-fb.png' && \OC::$server->getThemingDefaults()->shouldReplaceIcons()) { |
||
| 178 | $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
||
| 179 | if($app === '') { $app = 'core'; } |
||
| 180 | $path = $this->linkToRoute('theming.Icon.getTouchIcon', [ 'app' => $app ]) . '?v='. $cacheBusterValue; |
||
| 181 | } elseif (file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$image")) { |
||
| 182 | $path = \OC::$WEBROOT . "/themes/$theme/apps/$app/img/$image"; |
||
| 183 | } elseif (!file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$basename.svg") |
||
| 184 | && file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$basename.png")) { |
||
| 185 | $path = \OC::$WEBROOT . "/themes/$theme/apps/$app/img/$basename.png"; |
||
| 186 | } elseif (!empty($app) and file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$image")) { |
||
| 187 | $path = \OC::$WEBROOT . "/themes/$theme/$app/img/$image"; |
||
| 188 | View Code Duplication | } elseif (!empty($app) and (!file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$basename.svg") |
|
| 189 | && file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$basename.png"))) { |
||
| 190 | $path = \OC::$WEBROOT . "/themes/$theme/$app/img/$basename.png"; |
||
| 191 | } elseif (file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$image")) { |
||
| 192 | $path = \OC::$WEBROOT . "/themes/$theme/core/img/$image"; |
||
| 193 | View Code Duplication | } elseif (!file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$basename.svg") |
|
| 194 | && file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$basename.png")) { |
||
| 195 | $path = \OC::$WEBROOT . "/themes/$theme/core/img/$basename.png"; |
||
| 196 | } elseif ($appPath && file_exists($appPath . "/img/$image")) { |
||
| 197 | $path = \OC_App::getAppWebPath($app) . "/img/$image"; |
||
| 198 | } elseif ($appPath && !file_exists($appPath . "/img/$basename.svg") |
||
| 199 | && file_exists($appPath . "/img/$basename.png")) { |
||
| 200 | $path = \OC_App::getAppWebPath($app) . "/img/$basename.png"; |
||
| 201 | } elseif (!empty($app) and file_exists(\OC::$SERVERROOT . "/$app/img/$image")) { |
||
| 202 | $path = \OC::$WEBROOT . "/$app/img/$image"; |
||
| 203 | View Code Duplication | } elseif (!empty($app) and (!file_exists(\OC::$SERVERROOT . "/$app/img/$basename.svg") |
|
| 204 | && file_exists(\OC::$SERVERROOT . "/$app/img/$basename.png"))) { |
||
| 205 | $path = \OC::$WEBROOT . "/$app/img/$basename.png"; |
||
| 206 | } elseif (file_exists(\OC::$SERVERROOT . "/core/img/$image")) { |
||
| 207 | $path = \OC::$WEBROOT . "/core/img/$image"; |
||
| 208 | View Code Duplication | } elseif (!file_exists(\OC::$SERVERROOT . "/core/img/$basename.svg") |
|
| 209 | && file_exists(\OC::$SERVERROOT . "/core/img/$basename.png")) { |
||
| 210 | $path = \OC::$WEBROOT . "/themes/$theme/core/img/$basename.png"; |
||
| 211 | } |
||
| 212 | |||
| 213 | if($path !== '') { |
||
| 214 | $cache->set($cacheKey, $path); |
||
| 215 | return $path; |
||
| 216 | } else { |
||
| 217 | throw new RuntimeException('image not found: image:' . $image . ' webroot:' . \OC::$WEBROOT . ' serverroot:' . \OC::$SERVERROOT); |
||
| 218 | } |
||
| 219 | } |
||
| 220 | |||
| 257 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.