SystemParser::parse()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 3
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Codervio\Envmanager\Parser;
4
5
class SystemParser
6
{
7
    public static $isCalled = false;
8
    public static $sysvar = array();
9
10
    public function __construct()
11
    {
12
        if (!self::$isCalled) {
13
            self::$isCalled = true;
14
            self::$sysvar = static::parse();
15
        }
16
    }
17
18
    public static function parse()
19
    {
20
        if (function_exists('getenv')) {
21
            return getenv();
22
        }
23
24
        if (!empty($_ENV)) {
25
            return $_ENV;
26
        }
27
    }
28
29
    public static function getValues($variable = null)
30
    {
31
        if (!is_null($variable)) {
32
            if (isset(self::$sysvar[$variable])) {
33
                return self::$sysvar[$variable];
34
            } else {
35
                return null;
36
            }
37
        }
38
39
        return static::getAllEnvVariables();
40
    }
41
42
    public static function checkValue($variable)
43
    {
44
        if (isset(self::$sysvar[$variable])) {
45
            return true;
46
        }
47
48
        return false;
49
    }
50
51
    private static function getAllEnvVariables()
52
    {
53
        return static::$sysvar;
54
    }
55
}
56