helpers.php ➔ active()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 0
dl 0
loc 4
ccs 0
cts 1
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
if (! function_exists('mb_trim')) {
4
    /**
5
     * Strip whitespace (or other characters) from the beginning and end of a string.
6
     *
7
     * @see https://github.com/vanderlee/PHP-multibyte-functions/blob/master/functions/mb_trim.php
8
     *
9
     * @param  string  $string
10
     * @return string
11
     */
12
    function mb_trim($string)
13
    {
14 1
        return mb_ereg_replace('^\s*([\s\S]*?)\s*$', '\1', $string);
15
    }
16
}
17
18
if (! function_exists('string_value')) {
19
    /**
20
     * Converts any type to a string.
21
     *
22
     * @param  mixed  $value
23
     * @param  int  $jsonOptions  JSON_PRETTY_PRINT, etc
24
     * @return string
25
     */
26
    function string_value($value, $jsonOptions = 0)
27
    {
28 1
        if (is_string($value)) {
29
            return $value;
30
        }
31
32 1
        if (method_exists($value, '__toString')) {
33 1
            return (string) $value;
34
        }
35
36 1
        if (method_exists($value, 'toArray')) {
37 1
            $value = $value->toArray();
38
        }
39
40 1
        $jsonOptions |= JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES;
41
42 1
        return json_encode($value, $jsonOptions);
43
    }
44
}
45
46
if (! function_exists('in_arrayi')) {
47
    /**
48
     * Case-insensitive `in_array`.
49
     *
50
     * @see https://stackoverflow.com/a/2166524/521946
51
     * @see http://uk.php.net/manual/en/function.in-array.php#89256
52
     *
53
     * @param  string  $needle
54
     * @param  array  $haystack
55
     * @return bool
56
     */
57
    function in_arrayi($needle, $haystack)
58
    {
59 1
        return in_array(strtolower($needle), array_map('strtolower', $haystack));
60
    }
61
}
62
63
if (! function_exists('active')) {
64
    /**
65
     * Returns string 'active' if the current request URI matches the given patterns.
66
     *
67
     * @return string
68
     */
69
    function active()
70
    {
71
        return call_user_func_array([app('request'), 'is'], func_get_args()) ? 'active' : '';
72
    }
73
}
74
75
if (! function_exists('asset_from')) {
76
    /**
77
     * Generate the URL to an asset from a custom root domain such as CDN, etc.
78
     *
79
     * @param  string  $root
80
     * @param  string  $path
81
     * @param  bool|null  $secure
82
     * @return string
83
     */
84
    function asset_from($root, $path = '', $secure = null)
85
    {
86
        return app('url')->assetFrom($root, $path, $secure);
87
    }
88
}
89