Completed
Push — master ( cc9f19...85e40f )
by Pavel
11s
created

Settings   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 52
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B build() 0 46 5
1
<?php
2
3
namespace App\Common\Config;
4
5
use Exception;
6
7
class Settings
8
{
9
    /**
10
     * @return array of settings
0 ignored issues
show
Documentation introduced by
Should the return type not be null|array<string,array>?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
11
     */
12
    public static function build()
13
    {
14
        // Build application settings
15
16
        // Load settings from files
17
        try {
18
            // Directories list where config files located
19
            $directories = array(
20
                CONFIG_PATH,
21
            );
22
23
            // Locator to find files
24
            $locator = new FileLocator($directories);
25
26
            // Load config file into an array
27
            $loader = new PHPConfigLoader($locator);
28
29
            // Import all config sections
30
            $settings = $loader->importAll();
31
32
        } catch (Exception $ex) {
33
            die($ex->getMessage());
0 ignored issues
show
Coding Style Compatibility introduced by
The method build() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
34
        }
35
36
        // Load settings from ENV vars
37
        $settings['params']['env'] = @getenv('APPLICATION_ENV');
38
        $settings['accessToken']['secret_key'] = php_sapi_name() == 'cli-server' ? 'test-key' : @getenv('SECRET_KEY');
39
        $settings['accessToken']['iss'] = @getenv('AUTH_ISS');
40
41
        // Adjust error reporting
42
        if (@stripos($settings['params']['env'],  'dev') !== false) {
43
            $settings['displayErrorDetails'] = true;
44
        }
45
46
        if ($settings['displayErrorDetails']) {
47
            error_reporting(E_ALL);
48
        }
49
50
        // Adjust settings as Slim wants to have it - inside ['settings'] section
51
        $settings = [
52
            'settings' => $settings
53
        ];
54
55
        // Settings are ready
56
        return $settings;
57
    }
58
}
59