helpers.php ➔ config()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 16
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 4
nop 2
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * From Laravel
5
 * Illuminate/Foundation/helpers.php:444
6
 */
7
if(!function_exists('env')) {
8
    function env($key, $default = null) {
9
        $value = getenv($key);
10
11
        return ($value) ? : $default;
12
    }
13
}
14
15
if(!function_exists('load_dotenv')) {
16
    function load_dotenv($path = false, $file_name = ".env.example") {
17
        $path = ($path) ? : getcwd();
18
19
        if(file_exists($path . "/" . $file_name)) {
20
            $dot = new \Dotenv\Dotenv($path, $file_name);
0 ignored issues
show
Bug introduced by
It seems like $path defined by $path ?: getcwd() on line 17 can also be of type boolean; however, Dotenv\Dotenv::__construct() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
21
            $dot->load();
22
        }
23
    }
24
}
25
26
if(!function_exists('config')) {
27
    function config($path = false, $file_name = "config.yml") {
28
        $path = ($path) ? : getcwd();
29
30
        $config = [];
31
32
        if(file_exists($path . "/" . $file_name)) {
33
            /**
34
             * Get file from path command is run in
35
             */
36
            $config_yaml = file_get_contents($path . "/" . $file_name);
37
38
            $config = \Symfony\Component\Yaml\Yaml::parse($config_yaml);
39
        }
40
41
        return $config;
42
    }
43
}