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

Environment   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 40
ccs 0
cts 20
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A fetchConfig() 0 21 4
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
}