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.

StringHelper   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 125
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 15
lcom 1
cbo 0
dl 0
loc 125
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A isBool() 0 4 1
A isBoolInString() 0 4 3
A isNull() 0 4 1
A isNumber() 0 4 1
A isString() 0 4 2
A isVariableClone() 0 4 3
A startsWith() 0 4 2
A startsWithNumber() 0 4 1
A stripComments() 0 5 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     2.0.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 45
    public function isBool($value)
45
    {
46 45
        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 15
    public function isBoolInString($value, $quoted_string, $word_count)
59
    {
60 15
        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 42
    public function isNull($value)
71
    {
72 42
        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 42
    public function isNumber($value)
83
    {
84 42
        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 48
    public function isString($value)
95
    {
96 48
        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 21
    public function isVariableClone($value, $matches, $quoted_string)
109
    {
110 21
        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 60
    public function startsWith($string, $line)
122
    {
123 60
        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 51
    public function startsWithNumber($line)
134
    {
135 51
        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 45
    public function stripComments($value)
146
    {
147 45
        $value = explode(" #", $value, 2);
148 45
        return trim($value[0]);
149
    }
150
}
151