Conditions | 11 |
Paths | 16 |
Total Lines | 41 |
Code Lines | 29 |
Lines | 3 |
Ratio | 7.32 % |
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 |
||
33 | public function doFind($script) { |
||
34 | $fullScript = $this->addExtension($script); |
||
35 | $themeDirectory = $this->theme->getDirectory(); |
||
36 | $baseDirectory = $this->theme->getBaseDirectory(); |
||
37 | $webRoot = ''; |
||
38 | View Code Duplication | if ($baseDirectory !== $this->serverroot) { |
|
|
|||
39 | $webRoot = substr($this->theme->getWebPath(), 0, -strlen($themeDirectory)); |
||
40 | } |
||
41 | |||
42 | if (strpos($script, '/l10n/') !== false) { |
||
43 | // For language files we try to load them all, so themes can overwrite |
||
44 | // single l10n strings without having to translate all of them. |
||
45 | $found = 0; |
||
46 | $found += $this->appendOnceIfExist($this->serverroot, 'core/'.$fullScript); |
||
47 | $found += $this->appendOnceIfExist($baseDirectory, $themeDirectory.'/core/'.$fullScript, $webRoot); |
||
48 | $found += $this->appendOnceIfExist($this->serverroot, $fullScript); |
||
49 | $found += $this->appendOnceIfExist($baseDirectory, $themeDirectory.'/'.$fullScript, $webRoot); |
||
50 | $found += $this->appendOnceIfExist($baseDirectory, $themeDirectory.'/apps/'.$fullScript, $webRoot); |
||
51 | |||
52 | if ($found) { |
||
53 | return; |
||
54 | } |
||
55 | } else if ($this->appendOnceIfExist($baseDirectory, $themeDirectory.'/apps/'.$fullScript, $webRoot) |
||
56 | || $this->appendOnceIfExist($baseDirectory, $themeDirectory.'/'.$fullScript, $webRoot) |
||
57 | || $this->appendOnceIfExist($this->serverroot, $fullScript) |
||
58 | || $this->appendOnceIfExist($baseDirectory, $themeDirectory.'/core/'.$fullScript, $webRoot) |
||
59 | || $this->appendOnceIfExist($this->serverroot, 'core/'.$fullScript) |
||
60 | ) { |
||
61 | return; |
||
62 | } |
||
63 | |||
64 | $app = substr($fullScript, 0, strpos($fullScript, '/')); |
||
65 | $fullScript = substr($fullScript, strpos($fullScript, '/')+1); |
||
66 | $app_path = $this->appManager->getAppPath($app); |
||
67 | if( $app_path === false ) { return; } |
||
68 | $app_url = $this->appManager->getAppWebPath($app); |
||
69 | $app_url = ($app_url !== false) ? $app_url : null; |
||
70 | |||
71 | // missing translations files will be ignored |
||
72 | $this->appendOnceIfExist($app_path, $fullScript, $app_url); |
||
73 | } |
||
74 | |||
89 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.