| Conditions | 10 |
| Paths | 19 |
| Total Lines | 25 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 81 | public static function resolve(string $path):?string |
||
| 82 | { |
||
| 83 | if (file_exists($path)) { |
||
| 84 | return $path; |
||
| 85 | } else { |
||
| 86 | $ext = pathinfo($path, PATHINFO_EXTENSION); |
||
| 87 | if (empty($ext)) { |
||
| 88 | $basepath = $path; |
||
| 89 | } else { |
||
| 90 | $basepath = pathinfo($path, PATHINFO_FILENAME); |
||
| 91 | } |
||
| 92 | if (file_exists($conf = $basepath.'.yml') || file_exists($conf = $basepath.'.yaml')) { |
||
| 93 | if (function_exists('yaml_parse') || class_exists('Spyc')) { |
||
| 94 | return $conf; |
||
| 95 | } |
||
| 96 | } |
||
| 97 | if (file_exists($conf=$basepath.'.json')) { |
||
| 98 | return $conf; |
||
| 99 | } elseif (file_exists($conf=$basepath.'.php')) { |
||
| 100 | return $conf; |
||
| 101 | } elseif (file_exists($conf=$basepath.'.ini')) { |
||
| 102 | return $conf; |
||
| 103 | } |
||
| 104 | } |
||
| 105 | return null; |
||
| 106 | } |
||
| 136 |