Completed
Push — master ( fa0d52...fef7a6 )
by Arne
01:59
created

TildeExpansion   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 18
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A expand() 0 9 2
1
<?php
2
3
namespace Archivr;
4
5
class TildeExpansion
6
{
7
    /**
8
     * If a path relative to the user home is given this function expands the path to an absolute path.
9
     *
10
     * @param string $path
11
     * @return string
12
     */
13
    public static function expand(string $path): string
14
    {
15
        if (substr($path, 0, 1) === '~')
16
        {
17
            $path = posix_getpwuid(posix_getuid())['dir'] . substr($path, 1);
18
        }
19
20
        return $path;
21
    }
22
}
23