Passed
Pull Request — master (#40)
by Chema
03:06
created

GacelaJsonConfigFactory::createGacelaJsonConfig()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 12
ccs 6
cts 6
cp 1
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Framework\Config;
6
7
final class GacelaJsonConfigFactory implements GacelaJsonConfigFactoryInterface
8
{
9
    private string $applicationRootDir;
10
    private string $gacelaConfigFilename;
11
12 4
    public function __construct(
13
        string $applicationRootDir,
14
        string $gacelaConfigFilename
15
    ) {
16 4
        $this->applicationRootDir = $applicationRootDir;
17 4
        $this->gacelaConfigFilename = $gacelaConfigFilename;
18 4
    }
19
20 4
    public function createGacelaJsonConfig(): GacelaJsonConfig
21
    {
22 4
        $gacelaJsonPath = $this->applicationRootDir . '/' . $this->gacelaConfigFilename;
23
24 4
        if (is_file($gacelaJsonPath)) {
25
            /** @psalm-suppress MixedArgumentTypeCoercion */
26 3
            return GacelaJsonConfig::fromArray(
27 3
                (array)json_decode(file_get_contents($gacelaJsonPath), true)
28
            );
29
        }
30
31 1
        return GacelaJsonConfig::withDefaults();
32
    }
33
}
34