Unix   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 66.67%

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 6
cts 9
cp 0.6667
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A parseHomeDir() 0 16 5
1
<?php declare(strict_types=1);
2
/* (c) Anton Medvedev <[email protected]>
3
 *
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 */
7
8
namespace Deployer\Support;
9
10
class Unix
11
{
12
    /**
13
     * Expand leading tilde (~) symbol in given path.
14
     *
15
     * @param string $path
16
     * @return string
17
     */
18 1
    public static function parseHomeDir(string $path): string
19
    {
20 1
        if ('~' === $path || 0 === strpos($path, '~/')) {
21 1
            if (isset($_SERVER['HOME'])) {
22 1
                $home = $_SERVER['HOME'];
23
            } elseif (isset($_SERVER['HOMEDRIVE'], $_SERVER['HOMEPATH'])) {
24
                $home = $_SERVER['HOMEDRIVE'] . $_SERVER['HOMEPATH'];
25
            } else {
26
                return $path;
27
            }
28
29 1
            return $home . substr($path, 1);
30
        }
31
32 1
        return $path;
33
    }
34
}
35