| Conditions | 11 |
| Paths | 45 |
| Total Lines | 34 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 83 | public function findTemplate($template, $themes = []) { |
||
| 84 | |||
| 85 | if(is_array($template)) { |
||
| 86 | $type = array_key_exists('type', $template) ? $template['type'] : ''; |
||
| 87 | $templateList = array_key_exists('templates', $template) ? $template['templates'] : $template; |
||
| 88 | } |
||
| 89 | else { |
||
| 90 | $type = ''; |
||
| 91 | $templateList = array($template); |
||
| 92 | } |
||
| 93 | |||
| 94 | if(count($templateList) == 1 && substr($templateList[0], -3) == '.ss') { |
||
| 95 | return $templateList[0]; |
||
| 96 | } |
||
| 97 | |||
| 98 | foreach($templateList as $i => $template) { |
||
| 99 | $template = str_replace('\\', '/', $template); |
||
| 100 | $parts = explode('/', $template); |
||
| 101 | |||
| 102 | $tail = array_pop($parts); |
||
| 103 | $head = implode('/', $parts); |
||
| 104 | |||
| 105 | foreach($themes as $themename) { |
||
| 106 | $subthemes = isset($this->sets[$themename]) ? $this->sets[$themename]->getThemes() : [$themename]; |
||
| 107 | |||
| 108 | foreach($subthemes as $theme) { |
||
| 109 | $themePath = $this->base . '/' . $this->getPath($theme); |
||
| 110 | |||
| 111 | $path = $themePath . '/templates/' . implode('/', array_filter([$head, $type, $tail])) . '.ss'; |
||
| 112 | if (file_exists($path)) return $path; |
||
| 113 | } |
||
| 114 | } |
||
| 115 | } |
||
| 116 | } |
||
| 117 | |||
| 119 |
This checks looks for assignemnts to variables using the
list(...)function, where not all assigned variables are subsequently used.Consider the following code example.
Only the variables
$aand$care used. There was no need to assign$b.Instead, the list call could have been.