Passed
Push — develop ( 1e38ed...48b5ea )
by Brent
02:14
created

Config   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
dl 0
loc 43
ccs 15
cts 18
cp 0.8333
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 4 1
A all() 0 4 1
B init() 0 27 4
1
<?php
2
3
namespace Pageon;
4
5
use Dotenv\Dotenv;
6
use Dotenv\Exception\InvalidPathException;
7
use Illuminate\Support\Arr;
8
use Stitcher\Exception\InvalidConfiguration;
9
use Stitcher\File;
10
use Symfony\Component\Finder\Finder;
11
use Symfony\Component\Finder\SplFileInfo;
12
13
class Config
14
{
15
    protected static $env;
16
    protected static $loadedConfig = [];
17
18 6
    public static function init()
19
    {
20 6
        self::$env = new Dotenv(File::path());
21
22
        try {
23 6
            self::$env->load();
24
        } catch (InvalidPathException $e) {
25
            throw InvalidConfiguration::dotEnvNotFound(File::path());
26
        }
27
28 6
        $configFiles = Finder::create()->files()->in(File::path('config'))->name('*.php');
29
30 6
        $unparsedConfig = [];
31
32
        /** @var SplFileInfo $configFile */
33 6
        foreach ($configFiles as $configFile) {
34 6
            $fileConfig = require $configFile;
35
36 6
            if (!is_array($fileConfig)) {
37
                continue;
38
            }
39
40 6
            $unparsedConfig = array_merge($unparsedConfig, $fileConfig);
41
        }
42
43 6
        self::$loadedConfig = Arr::dot($unparsedConfig);
44 6
    }
45
46 4
    public static function get(string $key)
47
    {
48 4
        return self::$loadedConfig[$key] ?? null;
49
    }
50
51 1
    public static function all(): array
52
    {
53 1
        return self::$loadedConfig;
54
    }
55
}
56