Conditions | 10 |
Paths | 20 |
Total Lines | 25 |
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 |
||
116 | * |
||
117 | * resolvePath("test///.///me///../now/", true); |
||
118 | * => /home/example/test/now |
||
119 | * |
||
120 | * resolvePath("test/./me/../now/", "/www/example.com"); |
||
121 | * => /www/example.com/test/now |
||
122 | * |
||
123 | * resolvePath("/test/./me/../now/", "/www/example.com"); |
||
124 | * => /test/now |
||
125 | * |
||
126 | * @param string $path Absolute or relative path on filesystem |
||
127 | * @param mixed $basePath Resolve paths relatively to this path. Params: |
||
128 | * STRING: prefix with this path; |
||
129 | * TRUE: use current dir; |
||
130 | * FALSE: keep relative (default) |
||
131 | * |
||
132 | * @return string resolved path |
||
133 | */ |
||
134 | protected function resolvePath(string $path, $basePath = true): string |
||
135 | { |
||
136 | // Make absolute path |
||
137 | if (DIRECTORY_SEPARATOR !== $path[0]) { |
||
138 | if (true === $basePath) { |
||
139 | // Get PWD first to avoid getcwd() resolving symlinks if in symlinked folder |
||
140 | $path = (getenv('PWD') ?: getcwd()) . DIRECTORY_SEPARATOR . $path; |
||
141 | } elseif ('' !== $basePath) { |
||
160 |