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

Config::all()   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 0
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 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