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

Config   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 23 3
A get() 0 4 1
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