Conditions | 7 |
Paths | 7 |
Total Lines | 27 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 56 |
Changes | 1 | ||
Bugs | 1 | Features | 0 |
1 | <?php |
||
39 | public static function getAbsolutePath(string $path): string |
||
40 | { |
||
41 | if (strpos($path, 'https://') === 0) { |
||
42 | return $path; |
||
43 | } |
||
44 | if (strpos($path, 'http://') === 0) { |
||
45 | return $path; |
||
46 | } |
||
47 | if (strpos($path, '//') === 0) { |
||
48 | return $path; |
||
49 | } |
||
50 | |||
51 | $path = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $path); |
||
52 | $parts = array_filter(explode(DIRECTORY_SEPARATOR, $path), 'mb_strlen'); |
||
53 | $absolutes = []; |
||
54 | foreach ($parts as $part) { |
||
55 | if ('.' === $part) { |
||
56 | continue; |
||
57 | } |
||
58 | if ('..' === $part) { |
||
59 | array_pop($absolutes); |
||
60 | } |
||
61 | else { |
||
62 | $absolutes[] = $part; |
||
63 | } |
||
64 | } |
||
65 | return '/' . implode(DIRECTORY_SEPARATOR, $absolutes); |
||
66 | } |
||
68 |