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 ( 476db2...a33f7f )
by Miles
06:15
created

StringHelper::isString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

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 2
eloc 2
nc 2
nop 1
crap 2
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 trait for checking types
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 starts with a value
39
     *
40
     * @param string $string The value to search for
41
     * @param string $line   The line to test
42
     *
43
     * @return bool Returns if the line starts with value
44
     */
45 54
    public function startsWith($string, $line)
46
    {
47 54
        return $string === "" || strrpos($line, $string, -strlen($line)) !== false;
48
    }
49
50
    /**
51
     * Returns if value is a string
52
     *
53
     * @param string $value The value to test
54
     *
55
     * @return bool Is a value a string
56
     */
57 42
    public function isString($value)
58
    {
59 42
        return $this->startsWith('\'', $value) || $this->startsWith('"', $value);
60
    }
61
62
    /**
63
     * Returns if value is a bool
64
     *
65
     * @param string $value The value to test
66
     *
67
     * @return bool Is a value a bool
68
     */
69 39
    public function isBool($value)
70
    {
71 39
        return in_array(strtolower($value), self::$bool_variants);
72
    }
73
74
    /**
75
     * Returns if the bool is in a string
76
     *
77
     * @param string $value         The value to test
78
     * @param bool   $quoted_string Is the context a quoted string
79
     * @param int    $word_count    The amount of words in the sentence
80
     *
81
     * @return bool Is a value a bool in a string
82
     */
83 12
    public function isBoolInString($value, $quoted_string, $word_count)
84
    {
85 12
        return (is_bool($value)) && ($quoted_string || $word_count >= 2);
86
    }
87
88
    /**
89
     * Returns if value is number
90
     *
91
     * @param string $value The value to test
92
     *
93
     * @return bool Is a value a number
94
     */
95 36
    public function isNumber($value)
96
    {
97 36
        return is_numeric($value);
98
    }
99
100
    /**
101
     * Returns if value is null
102
     *
103
     * @param string $value The value to test
104
     *
105
     * @return bool Is a value null
106
     */
107 36
    public function isNull($value)
108
    {
109 36
        return $value === 'null';
110
    }
111
112
    /**
113
     * Returns if variable value is a clone, e.g. BOOL = $(BOOL_1)
114
     *
115
     * @param string $value         The value to test
116
     * @param array  $matches       The matches of the variables
117
     * @param bool   $quoted_string If the value is in a quoted string
118
     *
119
     * @return bool Is a value null
120
     */
121 18
    public function isVariableClone($value, $matches, $quoted_string)
122
    {
123 18
        return (count($matches[0]) === 1) && $value == $matches[0][0] && !$quoted_string;
124
    }
125
}
126