Passed
Push — master ( 800de6...ff9dd6 )
by Jean Paul
08:33
created

FileUtils::getUserHomePath()   A

Complexity

Conditions 5
Paths 6

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 5
c 1
b 0
f 0
nc 6
nop 0
dl 0
loc 12
rs 9.6111
1
<?php
2
3
namespace Coco\SourceWatcher\Utils;
4
5
/**
6
 * Class FileUtils
7
 *
8
 * @package Coco\SourceWatcher\Utils
9
 */
10
class FileUtils
11
{
12
    public static function file_build_path ( ...$segments ) : string
13
    {
14
        return join( DIRECTORY_SEPARATOR, $segments );
15
    }
16
17
    /**
18
     * // getenv("HOME") isn't set on windows and generates a Notice.
19
     *
20
     * @return string
21
     */
22
    public static function getUserHomePath () : string
23
    {
24
        $home = getenv( "HOME" );
25
26
        if ( empty( $home ) ) {
27
            if ( !empty( $_SERVER["HOMEDRIVE"] ) && !empty( $_SERVER["HOMEPATH"] ) ) {
28
                // home on windows
29
                $home = $_SERVER["HOMEDRIVE"] . $_SERVER["HOMEPATH"];
30
            }
31
        }
32
33
        return empty( $home ) ? "" : $home;
34
    }
35
}
36