Conditions | 6 |
Paths | 9 |
Total Lines | 37 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
30 | public static function getAbsolutePath(string $path): string |
||
31 | { |
||
32 | if (($expanded = static::expandTilde($path)) !== $path) |
||
33 | { |
||
34 | return $expanded; |
||
35 | } |
||
36 | |||
37 | $pathParts = array_filter(explode('/', $path), 'strlen'); |
||
38 | $absolutePathParts = []; |
||
39 | |||
40 | foreach ($pathParts as $part) |
||
41 | { |
||
42 | if ('.' == $part) |
||
43 | { |
||
44 | continue; |
||
45 | } |
||
46 | if ('..' == $part) |
||
47 | { |
||
48 | array_pop($absolutePathParts); |
||
49 | } |
||
50 | else |
||
51 | { |
||
52 | $absolutePathParts[] = $part; |
||
53 | } |
||
54 | } |
||
55 | |||
56 | $return = implode('/', $absolutePathParts); |
||
57 | |||
58 | if (substr($path, 0, 1) === '/') |
||
59 | { |
||
60 | return '/' . $return; |
||
61 | } |
||
62 | else |
||
63 | { |
||
64 | return getcwd() . '/' . $return; |
||
65 | } |
||
66 | } |
||
67 | } |
||
68 |