Passed
Push — master ( 72f8f4...a05bce )
by Jesús
07:47 queued 11s
created

ConfigFactory::getEnv()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
ccs 2
cts 2
cp 1
cc 2
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Framework\Config;
6
7
use Gacela\Framework\Config\PathNormalizer\AbsolutePathNormalizer;
8
use Gacela\Framework\Config\PathNormalizer\WithoutSuffixAbsolutePathStrategy;
9
use Gacela\Framework\Config\PathNormalizer\WithSuffixAbsolutePathStrategy;
10
11
final class ConfigFactory
12
{
13
    private const GACELA_PHP_CONFIG_FILENAME = 'gacela.php';
14
15
    private string $appRootDir;
16
17
    /** @var array<string,mixed> */
18
    private array $globalServices;
19
20
    /**
21
     * @param array<string,mixed> $globalServices
22
     */
23 24
    public function __construct(string $appRootDir, array $globalServices)
24
    {
25 24
        $this->appRootDir = $appRootDir;
26 24
        $this->globalServices = $globalServices;
27 24
    }
28
29 24
    public function createConfigLoader(): ConfigLoader
30
    {
31 24
        return new ConfigLoader(
32 24
            $this->createGacelaConfigFileFactory(),
33 24
            $this->createPathFinder(),
34 24
            $this->createPathNormalizer(),
35
        );
36
    }
37
38 24
    public function createGacelaConfigFileFactory(): GacelaConfigFileFactoryInterface
39
    {
40 24
        return new GacelaConfigFileFactory(
41 24
            $this->appRootDir,
42 24
            self::GACELA_PHP_CONFIG_FILENAME,
43 24
            $this->globalServices,
44 24
            $this->createConfigGacelaMapper()
45
        );
46
    }
47
48 24
    private function createPathFinder(): PathFinderInterface
49
    {
50 24
        return new PathFinder();
51
    }
52
53 24
    private function createConfigGacelaMapper(): ConfigGacelaMapper
54
    {
55 24
        return new ConfigGacelaMapper();
56
    }
57
58 24
    private function createPathNormalizer(): PathNormalizerInterface
59
    {
60 24
        return new AbsolutePathNormalizer([
61 24
            AbsolutePathNormalizer::WITHOUT_SUFFIX => new WithoutSuffixAbsolutePathStrategy($this->appRootDir),
62 24
            AbsolutePathNormalizer::WITH_SUFFIX => new WithSuffixAbsolutePathStrategy($this->appRootDir, $this->env()),
63
        ]);
64
    }
65
66 24
    private function env(): string
67
    {
68 24
        return getenv('APP_ENV') ?: '';
69
    }
70
}
71