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

Config::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
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