Passed
Push — v0.2 ( 260aa0...0508e4 )
by Freddie
03:04
created

Environment   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 35
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 7 1
A loadDotEnvParameters() 0 10 1
A getDotEnvFile() 0 4 1
1
<?php declare(strict_types=1);
2
3
namespace Simplex;
4
5
use Dotenv\Dotenv;
6
7
class Environment
8
{
9
    public const SIMPLEX_ENV = 'SIMPLEX_ENV';
10
    public const DEBUG_MODE = 'DEBUG_MODE';
11
    public const ENABLE_CACHE = 'ENABLE_CACHE';
12
    public const COMPILE_CONTAINER = 'COMPILE_CONTAINER';
13
14
    private const DOTENV_FILE_NAME = '.env';
15
16
    public function load(\SplFileInfo $projectRootDirectory): void
17
    {
18
        $dotEnvFile = $this->getDotEnvFile($projectRootDirectory);
19
20
        $this->loadDotEnvParameters($dotEnvFile);
21
22
        $this->loaded = true;
0 ignored issues
show
Bug Best Practice introduced by
The property loaded does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
23
    }
24
25
    private function getDotEnvFile(\SplFileInfo $projectRootDirectory): \SplFileInfo
26
    {
27
        return new \SplFileInfo(
28
            $projectRootDirectory->getPathname() . DIRECTORY_SEPARATOR . self::DOTENV_FILE_NAME
29
        );
30
    }
31
32
    private function loadDotEnvParameters(\SplFileInfo $dotEnvFile): void
33
    {
34
        $dotenv = new Dotenv($dotEnvFile->getPath());
35
36
        $dotenv->required(self::SIMPLEX_ENV)->notEmpty();
37
        $dotenv->required(self::ENABLE_CACHE)->isInteger();
38
        $dotenv->required(self::DEBUG_MODE)->isInteger();
39
        $dotenv->required(self::COMPILE_CONTAINER)->isInteger();
40
41
        $dotenv->load();
42
    }
43
}
44