GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( efb4df...2b441b )
by Miles
05:20 queued 02:52
created

StringHelper::startsWithNumber()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
/**
4
 * This file is part of the m1\env library
5
 *
6
 * (c) m1 <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * @package     m1/env
12
 * @version     1.1.0
13
 * @author      Miles Croxford <[email protected]>
14
 * @copyright   Copyright (c) Miles Croxford <[email protected]>
15
 * @license     http://github.com/m1/env/blob/master/LICENSE.md
16
 * @link        http://github.com/m1/env/blob/master/README.md Documentation
17
 */
18
19
namespace M1\Env\Helper;
20
21
/**
22
 * The class for string helping
23
 *
24
 * @since 1.1.0
25
 */
26
class StringHelper
27
{
28
    /**
29
     * The bool variants available in .env
30
     *
31
     * @var array $bool_variants
32
     */
33
    private static $bool_variants = array(
34
        'true', 'false', 'yes', 'no'
35
    );
36
37
    /**
38
     * Returns if value is a bool
39
     *
40
     * @param string $value The value to test
41
     *
42
     * @return bool Is a value a bool
43
     */
44 42
    public function isBool($value)
45
    {
46 42
        return in_array(strtolower($value), self::$bool_variants);
47
    }
48
49
    /**
50
     * Returns if the bool is in a string
51
     *
52
     * @param string $value         The value to test
53
     * @param bool   $quoted_string Is the context a quoted string
54
     * @param int    $word_count    The amount of words in the sentence
55
     *
56
     * @return bool Is a value a bool in a string
57
     */
58 12
    public function isBoolInString($value, $quoted_string, $word_count)
59
    {
60 12
        return (is_bool($value)) && ($quoted_string || $word_count >= 2);
61
    }
62
63
    /**
64
     * Returns if value is null
65
     *
66
     * @param string $value The value to test
67
     *
68
     * @return bool Is a value null
69
     */
70 39
    public function isNull($value)
71
    {
72 39
        return $value === 'null';
73
    }
74
75
    /**
76
     * Returns if value is number
77
     *
78
     * @param string $value The value to test
79
     *
80
     * @return bool Is a value a number
81
     */
82 39
    public function isNumber($value)
83
    {
84 39
        return is_numeric($value);
85
    }
86
87
    /**
88
     * Returns if value is a string
89
     *
90
     * @param string $value The value to test
91
     *
92
     * @return bool Is a value a string
93
     */
94 45
    public function isString($value)
95
    {
96 45
        return $this->startsWith('\'', $value) || $this->startsWith('"', $value);
97
    }
98
99
    /**
100
     * Returns if variable value is a clone, e.g. BOOL = $(BOOL_1)
101
     *
102
     * @param string $value         The value to test
103
     * @param array  $matches       The matches of the variables
104
     * @param bool   $quoted_string If the value is in a quoted string
105
     *
106
     * @return bool Is a value null
107
     */
108 18
    public function isVariableClone($value, $matches, $quoted_string)
109
    {
110 18
        return (count($matches[0]) === 1) && $value == $matches[0][0] && !$quoted_string;
111
    }
112
113
    /**
114
     * Returns if value starts with a value
115
     *
116
     * @param string $string The value to search for
117
     * @param string $line   The line to test
118
     *
119
     * @return bool Returns if the line starts with value
120
     */
121 57
    public function startsWith($string, $line)
122
    {
123 57
        return $string === "" || strrpos($line, $string, -strlen($line)) !== false;
124
    }
125
126
    /**
127
     * Returns if value starts with a number
128
     *
129
     * @param string $line   The line to test
130
     *
131
     * @return bool Returns if the line starts with a number
132
     */
133 48
    public function startsWithNumber($line)
134
    {
135 48
        return is_numeric(substr($line, 0, 1));
136
    }
137
138
    /**
139
     * Strips comments from a value
140
     *
141
     * @param string $value The value to strip comments from
142
     *
143
     * @return string value
144
     */
145 42
    public function stripComments($value)
146
    {
147 42
        $value = explode(" #", $value, 2);
148 42
        return trim($value[0]);
149
    }
150
}
151