Passed
Push — v2 ( 38427a...ff0552 )
by Brent
02:43
created

Config::init()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 12
nc 3
nop 1
dl 0
loc 23
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
    public static function init(string $basePath)
16
    {
17
        $basePath = rtrim($basePath, '/');
18
        self::$env = new Dotenv($basePath);
19
        self::$env->load();
20
21
        $configFiles = Finder::create()->files()->in($basePath . '/config')->name('*.php');
22
23
        $unparsedConfig = [];
24
25
        /** @var SplFileInfo $configFile */
26
        foreach ($configFiles as $configFile) {
27
            $fileConfig = require $configFile;
28
29
            if (!is_array($fileConfig)) {
30
                continue;
31
            }
32
33
            $unparsedConfig = array_merge($unparsedConfig, $fileConfig);
34
        }
35
36
        self::$loadedConfig = Arr::dot($unparsedConfig);
37
    }
38
39
    public static function get(string $key)
40
    {
41
        return self::$loadedConfig[$key] ?? null;
42
    }
43
}
44