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

Environment::loadDotEnvParameters()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 10
ccs 0
cts 7
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
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