Completed
Pull Request — master (#58)
by
unknown
03:23
created

Helpers.php ➔ env()   C

Complexity

Conditions 13
Paths 11

Size

Total Lines 25
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 182

Importance

Changes 0
Metric Value
cc 13
eloc 20
nc 11
nop 2
dl 0
loc 25
ccs 0
cts 19
cp 0
crap 182
rs 5.1234
c 0
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
/**
4
 * Determine if a given string starts with a given substring.
5
 *
6
 * @param  string $haystack
7
 * @param  string|array $needles
8
 * @return bool
9
 * @link https://github.com/laravel/framework/blob/43eeceda41cfec19fca6765e4e74f01caec20c5c/src/Illuminate/Support/Str.php#L466
10
 */
11 View Code Duplication
function startsWith($haystack, $needles)
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
12
{
13
    foreach ((array)$needles as $needle) {
14
        if ($needle !== '' && substr($haystack, 0, strlen($needle)) === (string)$needle) {
15
            return true;
16
        }
17
    }
18
    return false;
19
}
20
21
/**
22
 * Determine if a given string ends with a given substring.
23
 *
24
 * @param  string $haystack
25
 * @param  string|array $needles
26
 * @return bool
27
 * @link https://github.com/laravel/framework/blob/43eeceda41cfec19fca6765e4e74f01caec20c5c/src/Illuminate/Support/Str.php#L118
28
 */
29 View Code Duplication
function endsWith($haystack, $needles)
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
30
{
31
    foreach ((array)$needles as $needle) {
32
        if (substr($haystack, -strlen($needle)) === (string)$needle) {
33
            return true;
34
        }
35
    }
36
    return false;
37
}
38
39
/**
40
 * Return the default value of the given value.
41
 *
42
 * @param  mixed $value
43
 * @return mixed
44
 */
45
function value($value)
46
{
47
    return $value instanceof Closure ? $value() : $value;
48
}
49
50
/**
51
 * Gets the value of an environment variable.
52
 *
53
 * @param  string $key
54
 * @param  mixed $default
55
 * @return mixed
56
 * @link https://github.com/laravel/framework/blob/43eeceda41cfec19fca6765e4e74f01caec20c5c/src/Illuminate/Support/helpers.php#L595
57
 */
58
function env($key, $default = null)
59
{
60
    $value = getenv($key);
61
    if ($value === false) {
62
        return value($default);
63
    }
64
    switch (strtolower($value)) {
65
        case 'true':
66
        case '(true)':
67
            return true;
68
        case 'false':
69
        case '(false)':
70
            return false;
71
        case 'empty':
72
        case '(empty)':
73
            return '';
74
        case 'null':
75
        case '(null)':
76
            return;
77
    }
78
    if (strlen($value) > 1 && startsWith($value, '"') && endsWith($value, '"')) {
79
        return substr($value, 1, -1);
80
    }
81
    return $value;
82
}
83