DotEnvLoader   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 6
dl 0
loc 66
ccs 17
cts 17
cp 1
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 2
    public static function hasEnvironmentVariable($name)
29
    {
30 2
        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 1
    public static function loadFromConstant($constant, $file)
40
    {
41
        try {
42 1
            return DotEnvFactory::createFromConstant($constant, $file)->load();
43 1
        } catch (InvalidPathException $e) {
44 1
            throw new InvalidConstantPathException($e->getMessage(), $e->getCode(), $e);
45
        }
46
    }
47
48
    /**
49
     * @param string $variable
50
     * @param string $file
51
     * @return mixed[]
52
     * @throws \Abacaphiliac\ZendPhpDotEnv\Exception\InvalidEnvironmentVariablePathException
53
     */
54 1
    public static function loadFromEnvironmentVariable($variable, $file)
55
    {
56
        try {
57 1
            return DotEnvFactory::createFromEnvironmentVariable($variable, $file)->load();
58 1
        } catch (InvalidPathException $e) {
59 1
            throw new InvalidEnvironmentVariablePathException($e->getMessage(), $e->getCode(), $e);
60
        }
61
    }
62
63
    /**
64
     * @param string $file
65
     * @return mixed[]
66
     * @throws \Abacaphiliac\ZendPhpDotEnv\Exception\InvalidWorkingDirectoryPathException
67
     */
68 1
    public static function loadFromWorkingDirectory($file)
69
    {
70
        try {
71 1
            return DotEnvFactory::createFromWorkingDirectory($file)->load();
72 1
        } catch (InvalidPathException $e) {
73 1
            throw new InvalidWorkingDirectoryPathException($e->getMessage(), $e->getCode(), $e);
74
        }
75
    }
76
}
77