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

ConfigFactory   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 21
c 3
b 0
f 0
dl 0
loc 58
ccs 25
cts 25
cp 1
rs 10
wmc 8

7 Methods

Rating   Name   Duplication   Size   Complexity  
A createConfigLoader() 0 6 1
A createConfigGacelaMapper() 0 3 1
A createGacelaConfigFileFactory() 0 7 1
A __construct() 0 4 1
A createPathFinder() 0 3 1
A createPathNormalizer() 0 5 1
A env() 0 3 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