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

Helpers.php ➔ startsWith()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 9
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
eloc 5
nc 3
nop 2
dl 9
loc 9
ccs 0
cts 4
cp 0
crap 20
rs 9.2
c 0
b 0
f 0
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