| Conditions | 20 |
| Paths | 38 |
| Total Lines | 67 |
| Code Lines | 43 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 2 | Features | 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 |
||
| 48 | public function doFind($script) { |
||
| 49 | $theme_dir = 'themes/'.$this->theme.'/'; |
||
| 50 | |||
| 51 | // Extracting the appId and the script file name |
||
| 52 | $app = substr($script, 0, strpos($script, '/')); |
||
| 53 | $scriptName = basename($script); |
||
| 54 | |||
| 55 | if (strpos($script, '/l10n/') !== false) { |
||
| 56 | // For language files we try to load them all, so themes can overwrite |
||
| 57 | // single l10n strings without having to translate all of them. |
||
| 58 | $found = 0; |
||
| 59 | $found += $this->appendScriptIfExist($this->serverroot, 'core/'.$script); |
||
| 60 | $found += $this->appendScriptIfExist($this->serverroot, $theme_dir.'core/'.$script); |
||
| 61 | $found += $this->appendScriptIfExist($this->serverroot, $script); |
||
| 62 | $found += $this->appendScriptIfExist($this->serverroot, $theme_dir.$script); |
||
| 63 | $found += $this->appendScriptIfExist($this->serverroot, 'apps/'.$script); |
||
| 64 | $found += $this->appendScriptIfExist($this->serverroot, $theme_dir.'apps/'.$script); |
||
| 65 | |||
| 66 | if ($found) { |
||
| 67 | return; |
||
| 68 | } |
||
| 69 | } elseif ($this->appendScriptIfExist($this->serverroot, $theme_dir.'apps/'.$script) |
||
| 70 | || $this->appendScriptIfExist($this->serverroot, $theme_dir.$script) |
||
| 71 | || $this->appendScriptIfExist($this->serverroot, $script) |
||
| 72 | || $this->appendScriptIfExist($this->serverroot, $theme_dir."dist/$app-$scriptName") |
||
| 73 | || $this->appendScriptIfExist($this->serverroot, "dist/$app-$scriptName") |
||
| 74 | || $this->appendScriptIfExist($this->serverroot, 'apps/'.$script) |
||
| 75 | || $this->cacheAndAppendCombineJsonIfExist($this->serverroot, $script.'.json') |
||
| 76 | || $this->appendScriptIfExist($this->serverroot, $theme_dir.'core/'.$script) |
||
| 77 | || $this->appendScriptIfExist($this->serverroot, 'core/'.$script) |
||
| 78 | || (strpos($scriptName, '/') === -1 && ($this->appendScriptIfExist($this->serverroot, $theme_dir."dist/core-$scriptName") |
||
| 79 | || $this->appendScriptIfExist($this->serverroot, "dist/core-$scriptName"))) |
||
| 80 | || $this->cacheAndAppendCombineJsonIfExist($this->serverroot, 'core/'.$script.'.json') |
||
| 81 | ) { |
||
| 82 | return; |
||
| 83 | } |
||
| 84 | |||
| 85 | $script = substr($script, strpos($script, '/') + 1); |
||
| 86 | $app_url = null; |
||
|
|
|||
| 87 | |||
| 88 | try { |
||
| 89 | $app_url = $this->appManager->getAppWebPath($app); |
||
| 90 | } catch (AppPathNotFoundException) { |
||
| 91 | // pass |
||
| 92 | } |
||
| 93 | |||
| 94 | try { |
||
| 95 | $app_path = $this->appManager->getAppPath($app); |
||
| 96 | |||
| 97 | // Account for the possibility of having symlinks in app path. Only |
||
| 98 | // do this if $app_path is set, because an empty argument to realpath |
||
| 99 | // gets turned into cwd. |
||
| 100 | $app_path = realpath($app_path); |
||
| 101 | |||
| 102 | // missing translations files will be ignored |
||
| 103 | if (strpos($script, 'l10n/') === 0) { |
||
| 104 | $this->appendScriptIfExist($app_path, $script, $app_url); |
||
| 105 | return; |
||
| 106 | } |
||
| 107 | |||
| 108 | if (!$this->cacheAndAppendCombineJsonIfExist($app_path, $script.'.json', $app)) { |
||
| 109 | $this->appendScriptIfExist($app_path, $script, $app_url); |
||
| 110 | } |
||
| 111 | } catch (AppPathNotFoundException) { |
||
| 112 | $this->logger->error('Could not find resource {resource} to load', [ |
||
| 113 | 'resource' => $app . '/' . $script . '.js', |
||
| 114 | 'app' => 'jsresourceloader', |
||
| 115 | ]); |
||
| 160 |