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.

Expression   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 115
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 16
lcom 0
cbo 0
dl 0
loc 115
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A boolString() 0 4 2
A listString() 0 6 1
A arrayString() 0 6 1
B analyze() 0 24 7
A toString() 0 6 5
1
<?php
2
/*
3
4
MIT License
5
Copyright 2013-2020 Zordius Chen. All Rights Reserved.
6
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9
10
Origin: https://github.com/zordius/lightncandy
11
*/
12
13
/**
14
 * file of LightnCandy Expression handler
15
 *
16
 * @package    LightnCandy
17
 * @author     Zordius <[email protected]>
18
 */
19
20
namespace LightnCandy;
21
22
/**
23
 * LightnCandy Expression handler
24
 */
25
class Expression
26
{
27
    /**
28
     * return 'true' or 'false' string.
29
     *
30
     * @param integer $v value
31
     *
32
     * @return string 'true' when the value larger then 0
33
     *
34
     * @expect 'true' when input 1
35
     * @expect 'true' when input 999
36
     * @expect 'false' when input 0
37
     * @expect 'false' when input -1
38
     */
39 718
    public static function boolString($v)
40
    {
41 718
        return ($v > 0) ? 'true' : 'false';
42
    }
43
44
    /**
45
     * Get string presentation for a string list
46
     *
47
     * @param array<string> $list an array of strings.
48
     *
49
     * @return string PHP list string
50
     *
51
     * @expect '' when input array()
52
     * @expect "'a'" when input array('a')
53
     * @expect "'a','b','c'" when input array('a', 'b', 'c')
54
     */
55 392
    public static function listString($list)
56
    {
57
        return implode(',', (array_map(function ($v) {
58 391
            return "'$v'";
59 392
        }, $list)));
60
    }
61
62
    /**
63
     * Get string presentation for an array
64
     *
65
     * @param array<string> $list an array of variable names.
66
     *
67
     * @return string PHP array names string
68
     *
69
     * @expect '' when input array()
70
     * @expect "['a']" when input array('a')
71
     * @expect "['a']['b']['c']" when input array('a', 'b', 'c')
72
     */
73 139
    public static function arrayString($list)
74
    {
75
        return implode('', (array_map(function ($v) {
76 137
            return "['$v']";
77 139
        }, $list)));
78
    }
79
80
    /**
81
     * Analyze an expression
82
     *
83
     * @param array<string,array|string|integer> $context Current context
84
     * @param array<array|string|integer> $var variable parsed path
85
     *
86
     * @return array<integer|boolean|array> analyzed result
87
     *
88
     * @expect array(0, false, array('foo')) when input array('flags' => array('spvar' => 0)), array(0, 'foo')
89
     * @expect array(1, false, array('foo')) when input array('flags' => array('spvar' => 0)), array(1, 'foo')
90
     */
91 645
    public static function analyze($context, $var)
92
    {
93 645
        $levels = 0;
94 645
        $spvar = false;
95
96 645
        if (isset($var[0])) {
97
            // trace to parent
98 606
            if (!is_string($var[0]) && is_int($var[0])) {
99 50
                $levels = array_shift($var);
100
            }
101
        }
102
103 645
        if (isset($var[0])) {
104
            // handle @root, @index, @key, @last, etc
105 603
            if ($context['flags']['spvar']) {
106 425
                if (substr($var[0], 0, 1) === '@') {
107 39
                    $spvar = true;
108 39
                    $var[0] = substr($var[0], 1);
109
                }
110
            }
111
        }
112
113 645
        return array($levels, $spvar, $var);
114
    }
115
116
    /**
117
     * get normalized handlebars expression for a variable
118
     *
119
     * @param integer $levels trace N levels top parent scope
120
     * @param boolean $spvar is the path start with @ or not
121
     * @param array<string|integer> $var variable parsed path
122
     *
123
     * @return string normalized expression for debug display
124
     *
125
     * @expect '[a].[b]' when input 0, false, array('a', 'b')
126
     * @expect '@[root]' when input 0, true, array('root')
127
     * @expect 'this' when input 0, false, null
128
     * @expect 'this.[id]' when input 0, false, array(null, 'id')
129
     * @expect '@[root].[a].[b]' when input 0, true, array('root', 'a', 'b')
130
     * @expect '../../[a].[b]' when input 2, false, array('a', 'b')
131
     * @expect '../[a\'b]' when input 1, false, array('a\'b')
132
     */
133 645
    public static function toString($levels, $spvar, $var)
134
    {
135
        return ($spvar ? '@' : '') . str_repeat('../', $levels) . ((is_array($var) && count($var)) ? implode('.', array_map(function ($v) {
136 603
            return ($v === null) ? 'this' : "[$v]";
137 645
        }, $var)) : 'this');
138
    }
139
}
140