Completed
Push — dev-master ( fd5e6f...6800b7 )
by Derek Stephen
02:07
created

Environment::fetchConfig()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 0
cts 16
cp 0
rs 9.584
c 0
b 0
f 0
cc 4
nc 4
nop 2
crap 20
1
<?php
2
3
namespace Bone\Server;
4
5
use Bone\Traits\HasAttributesTrait;
6
7
class Environment
8
{
9
    use HasAttributesTrait;
10
11
    /**
12
     * Environment constructor.
13
     * @param array $serverGlobals
14
     */
15
    public function __construct(array $serverGlobals)
16
    {
17
        $this->setAttributes($serverGlobals);
18
    }
19
20
    /**
21
     * @param string $configFolder
22
     * @param string $applicationEnvironment
23
     * @return array
24
     */
25
    public function fetchConfig(string $configFolder, string $applicationEnvironment) : array
26
    {
27
        $config = [];
28
29
        // load the config.php if it exists
30
        $path = $configFolder . '/config.php';
31
        if (file_exists($path)) {
32
            $config = require_once $path;
33
        }
34
35
        // check environment config folder exists
36
        $path = $configFolder . '/' . $applicationEnvironment;
37
        if (file_exists($path)) {
38
            $files = glob($path . '/*.php');
39
            foreach ($files as $file) {
40
                $config = array_merge($config, require_once $file);
41
            }
42
        }
43
44
        return $config;
45
    }
46
}