Passed
Push — v2 ( 7b6778...2ad6b9 )
by Brent
05:06
created

Config::init()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 3.004

Importance

Changes 0
Metric Value
cc 3
eloc 12
nc 3
nop 1
dl 0
loc 23
ccs 12
cts 13
cp 0.9231
crap 3.004
rs 9.0856
c 0
b 0
f 0
1
<?php
2
3
namespace Pageon;
4
5
use Dotenv\Dotenv;
6
use Illuminate\Support\Arr;
7
use Symfony\Component\Finder\Finder;
8
use Symfony\Component\Finder\SplFileInfo;
9
10
class Config
11
{
12
    protected static $env;
13
    protected static $loadedConfig = [];
14
15 6
    public static function init(string $basePath)
16
    {
17 6
        $basePath = rtrim($basePath, '/');
18 6
        self::$env = new Dotenv($basePath);
19 6
        self::$env->load();
20
21 6
        $configFiles = Finder::create()->files()->in($basePath . '/config')->name('*.php');
22
23 6
        $unparsedConfig = [];
24
25
        /** @var SplFileInfo $configFile */
26 6
        foreach ($configFiles as $configFile) {
27 6
            $fileConfig = require $configFile;
28
29 6
            if (!is_array($fileConfig)) {
30
                continue;
31
            }
32
33 6
            $unparsedConfig = array_merge($unparsedConfig, $fileConfig);
34
        }
35
36 6
        self::$loadedConfig = Arr::dot($unparsedConfig);
37 6
    }
38
39 4
    public static function get(string $key)
40
    {
41 4
        return self::$loadedConfig[$key] ?? null;
42
    }
43
44 1
    public static function all(): array
45
    {
46 1
        return self::$loadedConfig;
47
    }
48
}
49