Completed
Pull Request — master (#9)
by
unknown
15:39
created

DotEnvLoader   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 29.4%

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 3
dl 0
loc 66
ccs 5
cts 17
cp 0.294
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getEnvironmentVariable() 0 6 1
A hasEnvironmentVariable() 0 4 1
A loadFromConstant() 0 8 2
A loadFromEnvironmentVariable() 0 8 2
A loadFromWorkingDirectory() 0 8 2
1
<?php
2
3
namespace Abacaphiliac\ZendPhpDotEnv;
4
5
use Abacaphiliac\ZendPhpDotEnv\Exception\InvalidConstantPathException;
6
use Abacaphiliac\ZendPhpDotEnv\Exception\InvalidEnvironmentVariablePathException;
7
use Abacaphiliac\ZendPhpDotEnv\Exception\InvalidWorkingDirectoryPathException;
8
use Dotenv\Exception\InvalidPathException;
9
use Dotenv\Loader;
10
11
class DotEnvLoader
12
{
13
    /**
14
     * @param string $name
15
     * @return string
16
     */
17 3
    public static function getEnvironmentVariable($name)
18
    {
19 3
        $loader = new Loader(__DIR__);
20
        
21 3
        return $loader->getEnvironmentVariable($name);
22
    }
23
    
24
    /**
25
     * @param string $name
26
     * @return string
27
     */
28 1
    public static function hasEnvironmentVariable($name)
29
    {
30 1
        return (bool) self::getEnvironmentVariable($name);
31
    }
32
33
    /**
34
     * @param string $constant
35
     * @param string $file
36
     * @return mixed[]
37
     * @throws \Abacaphiliac\ZendPhpDotEnv\Exception\InvalidConstantPathException
38
     */
39
    public static function loadFromConstant($constant, $file)
40
    {
41
        try {
42
            return DotEnvFactory::createFromConstant($constant, $file)->load();
43
        } catch (InvalidPathException $e) {
44
            //
45
        }
46
    }
47
48
    /**
49
     * @param string $variable
50
     * @param string $file
51
     * @return mixed[]
52
     * @throws \Abacaphiliac\ZendPhpDotEnv\Exception\InvalidEnvironmentVariablePathException
53
     */
54
    public static function loadFromEnvironmentVariable($variable, $file)
55
    {
56
        try {
57
            return DotEnvFactory::createFromEnvironmentVariable($variable, $file)->load();
58
        } catch (InvalidPathException $e) {
59
            //
60
        }
61
    }
62
63
    /**
64
     * @param string $file
65
     * @return mixed[]
66
     * @throws \Abacaphiliac\ZendPhpDotEnv\Exception\InvalidWorkingDirectoryPathException
67
     */
68
    public static function loadFromWorkingDirectory($file)
69
    {
70
        try {
71
            return DotEnvFactory::createFromWorkingDirectory($file)->load();
72
        } catch (InvalidPathException $e) {
73
            //
74
        }
75
    }
76
}
77