Failed Conditions
Push — experimental/3.1 ( 36d064...2457e2 )
by Kiyotaka
128:07 queued 120:55
created

env.php ➔ env()   C

Complexity

Conditions 8
Paths 8

Size

Total Lines 33
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 19
nc 8
nop 2
dl 0
loc 33
rs 5.3846
c 0
b 0
f 0
1
<?php
2
3
function env($key, $default = null)
0 ignored issues
show
Coding Style introduced by
Consider putting global function "env" in a static class
Loading history...
introduced by
Missing function doc comment
Loading history...
4
{
5
    $value = getenv($key);
6
7
    if ($value === false) {
8
        return $default;
9
    }
10
11
    if (is_array($value)) {
12
        return $value;
13
    }
14
15
    switch (strtolower($value))
16
    {
17
        case 'true':
18
            return true;
19
        case 'false':
20
            return false;
21
        case 'null':
22
            return null;
23
    }
24
25
    if ($value === '') {
26
        return $value;
27
    }
28
29
    $decoded = json_decode($value);
30
    if ($decoded !== null) {
31
        return $decoded;
32
    }
33
34
    return $value;
35
}
36