env.php ➔ env()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 10
nc 4
nop 2
dl 0
loc 19
rs 9.2
c 0
b 0
f 0
1
<?php
2
/*
3
 * This file is part of the Borobudur-DependencyInjection package.
4
 *
5
 * (c) Hexacodelabs <http://hexacodelabs.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
if (!function_exists('setenv')) {
12
    /**
13
     * Set environment variable.
14
     *
15
     * @param string $name
16
     * @param mixed  $value
17
     *
18
     * @author      Iqbal Maulana <[email protected]>
19
     * @created     8/22/15
20
     */
21
    function setenv($name, $value)
22
    {
23
        if (false === $value) {
24
            $value = '(false)';
25
        } elseif (true === $value) {
26
            $value = '(true)';
27
        }
28
29
        putenv(sprintf('%s=%s', strtoupper($name), $value));
30
    }
31
}
32
33
if (!function_exists('env')) {
34
    /**
35
     * Get environment variable.
36
     *
37
     * @param string $name
38
     * @param mixed  $default
39
     *
40
     * @return mixed
41
     *
42
     * @author      Iqbal Maulana <[email protected]>
43
     * @created     8/22/15
44
     */
45
    function env($name, $default = null)
46
    {
47
        $name = strtoupper($name);
48
        $value = getenv($name);
49
50
        if (false === $value) {
51
            return $default;
52
        }
53
54
        if ('(false)' === $value) {
55
            return false;
56
        }
57
58
        if ('(true)' === $value) {
59
            return true;
60
        }
61
62
        return $value;
63
    }
64
}
65