HomePathService::getHomePath()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 10
nc 4
nop 0
dl 0
loc 19
rs 9.9332
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of Phiremock.
4
 *
5
 * Phiremock is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU Lesser General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * Phiremock is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with Phiremock.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18
19
namespace Mcustiel\Phiremock\Server\Utils;
20
21
use Exception;
22
use Mcustiel\Phiremock\Server\Utils\Config\Directory;
23
24
class HomePathService
25
{
26
    /** @throws Exception */
27
    public static function getHomePath(): Directory
28
    {
29
        $unixHome = getenv('HOME');
30
31
        if (!empty($unixHome)) {
32
            return new Directory($unixHome);
33
        }
34
35
        $windowsHome = getenv('USERPROFILE');
36
        if (!empty($windowsHome)) {
37
            return new Directory($windowsHome);
38
        }
39
40
        $windowsHome = getenv('HOMEPATH');
41
        if (!empty($windowsHome)) {
42
            return new Directory(getenv('HOMEDRIVE') . getenv('HOMEPATH'));
43
        }
44
45
        throw new Exception('Could not get the users\'s home path');
46
    }
47
}
48