Settings   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 49
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B build() 0 27 2
1
<?php
2
3
namespace App\Common\Config;
4
5
use Dotenv\Dotenv;
6
7
class Settings
8
{
9
    /**
10
     * @var array
11
     */
12
    private static $requiredVariable = [
13
        'DB_HOST',
14
        'DB_NAME',
15
        'DB_USER',
16
        'DB_PASS',
17
        'APP_HOST',
18
        'APP_API_HOST',
19
        'APP_ENV',
20
        'AUTH_SECRET_KEY',
21
        'AUTH_ALLOW_HOSTS'
22
    ];
23
24
    /**
25
     * @return array - array of settings
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<string,array>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
26
     * @throws \Symfony\Component\Config\Exception\FileLoaderLoadException
27
     */
28
    public static function build()
29
    {
30
        $dotenv = new Dotenv(ROOT_PATH);
31
        $dotenv->load();
32
        $dotenv->required(self::$requiredVariable);
33
34
        // Locator to find files
35
        $locator = new FileLocator([
36
            CONFIG_PATH,
37
        ]);
38
39
        // Load config file into an array
40
        $loader = new PHPConfigLoader($locator);
41
42
        // Import all config sections
43
        $settings = $loader->importAll();
44
45
        // Adjust error reporting
46
        if (stripos($settings['params']['env'], 'dev') !== false) {
47
            $settings['displayErrorDetails'] = true;
48
            error_reporting(E_ALL);
49
        }
50
51
        return [
52
            'settings' => $settings,
53
        ];
54
    }
55
}
56