Environment   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 22.22%

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 7
c 4
b 0
f 1
lcom 1
cbo 2
dl 0
loc 35
ccs 4
cts 18
cp 0.2222
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 3
A load() 0 5 1
A get() 0 8 3
1
<?php namespace GameScan\Core\Tools;
2
3
use Dotenv;
4
use GameScan\Core\Exceptions\EnvironmentException;
5
6
class Environment
7
{
8
9
    private $path = null;
10
    private $hasLoadValues = false;
11
12 2
    public function __construct($path = null, $filename = ".env")
13
    {
14 2
        if ($path === null) {
15
            $path = __DIR__ . '/../../../../..';
16
        }
17
18 2
        if (!file_exists($path . DIRECTORY_SEPARATOR . $filename)) {
19 2
            throw new EnvironmentException($path . DIRECTORY_SEPARATOR . $filename . " is not exist. Please create an environment file before using this feature");
20
        }
21
22
        $this->path = $path;
23
    }
24
25
26
    public function load()
27
    {
28
        Dotenv::load($this->path);
29
        $this->hasLoadValues = true;
30
    }
31
32
    public function get($key, $defaultValue = false)
33
    {
34
        if (!$this->hasLoadValues) {
35
            $this->load();
36
        }
37
        $value = getenv($key);
38
        return $value !== false ? $value : $defaultValue;
39
    }
40
}
41