Test Failed
Push — v0.2 ( 26788c...260aa0 )
by Freddie
05:28
created

Environment::getDefaultCacheDirectory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
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 2
    private function loadDotEnvParameters(\SplFileInfo $dotEnvFile): void
33
    {
34 2
        $dotenv = new Dotenv($dotEnvFile->getPath());
35
36 2
        $dotenv->required(self::SIMPLEX_ENV)->notEmpty();
37
        $dotenv->required(self::ENABLE_CACHE)->isInteger();
38 2
        $dotenv->required(self::DEBUG_MODE)->isInteger();
39
        $dotenv->required(self::COMPILE_CONTAINER)->isInteger();
40 2
41
        $dotenv->load();
42 2
    }
43
}
44