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