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

Config   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 94.12%

Importance

Changes 0
Metric Value
dl 0
loc 39
ccs 16
cts 17
cp 0.9412
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 3

3 Methods

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