Passed
Branch master (fc4881)
by Eugene
03:18
created

env.php ➔ env()   D

Complexity

Conditions 10
Paths 10

Size

Total Lines 29
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 10
eloc 18
nc 10
nop 2
dl 0
loc 29
rs 4.8196
c 1
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
// Environments helpers from Laravel Framework
4
if (!function_exists('value'))
5
{
6
    /**
7
     * Return the default value of the given value.
8
     *
9
     * @param  mixed  $value
10
     * @return mixed
11
     */
12
    function value($value)
13
    {
14
        return $value instanceof Closure ? $value() : $value;
15
    }
16
}
17
if (!function_exists('env'))
18
{
19
    /**
20
     * Gets the value of an environment variable. Supports boolean, empty and null.
21
     *
22
     * @param  string  $key
23
     * @param  mixed   $default
24
     * @return mixed
25
     */
26
    function env($key, $default = null)
27
    {
28
        $value = getenv($key);
29
30
        if ($value === false) {
31
            return value($default);
32
        }
33
34
        switch (strtolower($value))
35
        {
36
            case 'true':
37
            case '(true)':
38
                return true;
39
40
            case 'false':
41
            case '(false)':
42
                return false;
43
44
            case 'empty':
45
            case '(empty)':
46
                return '';
47
48
            case 'null':
49
            case '(null)':
50
                return;
51
        }
52
53
        return $value;
54
    }
55
}
56