Passed
Push — master ( 6b9d0f...15df05 )
by Alec
06:11
created

typeOf()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 2
c 1
b 0
f 1
nc 2
nop 1
dl 0
loc 4
ccs 1
cts 1
cp 1
crap 2
rs 10
1
<?php
2
/**
3
 * User: alec
4
 * Date: 12.10.18
5
 * Time: 13:21
6
 */
7
8
if (!\defined('HELPERS_STR_TRUE')) {
9
    define('HELPERS_STR_TRUE', 'true');
10
}
11
if (!\defined('HELPERS_STR_FALSE')) {
12
    define('HELPERS_STR_FALSE', 'false');
13
}
14
if (!\defined('HELPERS_STR_EMPTY')) {
15
    define('HELPERS_STR_EMPTY', 'empty');
16
}
17
if (!\defined('HELPERS_STR_NULL')) {
18
    define('HELPERS_STR_NULL', 'null');
19
}
20
21
22
if (!function_exists('env')) {
23
    /**
24
     * Gets the value of an environment variable.
25
     *
26
     * @param  string $key
27
     * @param  mixed $default
28
     * @return mixed
29
     */
30
    function env($key, $default = null)
31
    {
32 38
        if (false === $value = getenv($key)) {
33 18
            $value = value($default);
34
        }
35
36 38
        $value = \ltrim(\rtrim($value, ')"'), '("');
37
38 38
        switch (strtolower($value)) {
39 38
            case HELPERS_STR_TRUE:
40 4
                $value = true;
41 4
                break;
42 34
            case HELPERS_STR_FALSE:
43 4
                $value = false;
44 4
                break;
45 30
            case HELPERS_STR_EMPTY:
46 26
            case HELPERS_STR_NULL:
47 8
                $value = '';
48 8
                break;
49
        }
50
51 38
        return $value;
52
    }
53
}
54
55
if (!function_exists('value')) {
56
    /**
57
     * Return the default value of the given value.
58
     *
59
     * @param  mixed $value
60
     * @return mixed
61
     */
62
    function value($value)
63
    {
64
        return
65 18
            $value instanceof Closure ?
66 18
                $value() : $value;
67
    }
68
}
69
70
if (!function_exists('typeOf')) {
71
    /**
72
     * Returns the type of a variable.
73
     *
74
     * @param mixed $var
75
     * @return string
76
     */
77
    function typeOf($var): string
78
    {
79
        return
80 9
            \is_object($var) ? \get_class($var) : \gettype($var);
81
    }
82
}
83