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 — v0.89-develop ( 43fc06...9799ea )
by Zordius
02:32
created

Expression   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 16
c 4
b 0
f 0
lcom 0
cbo 0
dl 0
loc 108
ccs 28
cts 28
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A boolString() 0 3 2
A listString() 0 5 1
A arrayString() 0 5 1
C analyze() 0 23 7
B toString() 0 5 5
1
<?php
2
/*
3
4
Copyrights for code authored by Yahoo! Inc. is licensed under the following terms:
5
MIT License
6
Copyright (c) 2013-2015 Yahoo! Inc. All Rights Reserved.
7
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:
8
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
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.
10
11
Origin: https://github.com/zordius/lightncandy
12
*/
13
14
/**
15
 * file of LightnCandy Expression handler
16
 *
17
 * @package    LightnCandy
18
 * @author     Zordius <[email protected]>
19
 */
20
21
namespace LightnCandy;
22
23
use \LightnCandy\Validator;
24
use \LightnCandy\Token;
25
26
/**
27
 * LightnCandy Expression handler
28
 */
29
class Expression
30
{
31
    /**
32
     * return 'true' or 'false' string.
33
     *
34
     * @param integer $v value
35
     *
36
     * @return string 'true' when the value larger then 0
37
     *
38
     * @expect 'true' when input 1
39
     * @expect 'true' when input 999
40
     * @expect 'false' when input 0
41
     * @expect 'false' when input -1
42
     */
43 576
    public static function boolString($v) {
44 576
        return ($v > 0) ? 'true' : 'false';
45
    }
46
47
    /**
48
     * Get string presentation for a string list
49
     *
50
     * @param array<string> $list an array of strings.
51
     *
52
     * @return string PHP list string
53
     *
54
     * @expect '' when input array()
55
     * @expect "'a'" when input array('a')
56
     * @expect "'a','b','c'" when input array('a', 'b', 'c')
57
     */
58 341
    public static function listString($list) {
59
        return implode(',', (array_map(function ($v) {
60 341
            return "'$v'";
61 341
        }, $list)));
62
    }
63
64
    /**
65
     * Get string presentation for an array
66
     *
67
     * @param array<string> $list an array of variable names.
68
     *
69
     * @return string PHP array names string
70
     *
71
     * @expect '' when input array()
72
     * @expect "['a']" when input array('a')
73
     * @expect "['a']['b']['c']" when input array('a', 'b', 'c')
74
     */
75 99
    public static function arrayString($list) {
76
        return implode('', (array_map(function ($v) {
77 99
            return "['$v']";
78 99
        }, $list)));
79
    }
80
81
    /**
82
     * Analyze an expression
83
     *
84
     * @param array<string,array|string|integer> $context Current context
85
     * @param array<array|string|integer> $var variable parsed path
86
     *
87
     * @return array<integer|boolean|array> analyzed result
0 ignored issues
show
Documentation introduced by
Should the return type not be array<array|string|integer|null|boolean>?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
88
     *
89
     */
90 514
    public static function analyze($context, $var) {
91 514
        $levels = 0;
92 514
        $spvar = false;
93
94 514
        if (isset($var[0])) {
95
            // trace to parent
96 485
            if (!is_string($var[0]) && is_int($var[0])) {
97 35
                $levels = array_shift($var);
98 35
            }
99 485
        }
100
101 514
        if (isset($var[0])) {
102
            // handle @root, @index, @key, @last, etc
103 482
            if ($context['flags']['spvar']) {
104 324
                if (substr($var[0], 0, 1) === '@') {
105 36
                    $spvar = true;
106 36
                    $var[0] = substr($var[0], 1);
107 36
                }
108 324
            }
109 482
        }
110
111 514
        return array($levels, $spvar, $var);
112
    }
113
114
    /**
115
     * get normalized handlebars expression for a variable
116
     *
117
     * @param integer $levels trace N levels top parent scope
118
     * @param boolean $spvar is the path start with @ or not
119
     * @param array<string|integer> $var variable parsed path
120
     *
121
     * @return string normalized expression for debug display
122
     *
123
     * @expect '[a].[b]' when input 0, false, array('a', 'b')
124
     * @expect '@[root]' when input 0, true, array('root')
125
     * @expect 'this' when input 0, false, null
126
     * @expect 'this.[id]' when input 0, false, array(null, 'id')
127
     * @expect '@[root].[a].[b]' when input 0, true, array('root', 'a', 'b')
128
     * @expect '../../[a].[b]' when input 2, false, array('a', 'b')
129
     * @expect '../[a\'b]' when input 1, false, array('a\'b')
130
     */
131
    public static function toString($levels, $spvar, $var) {
132 515
        return ($spvar ? '@' : '') . str_repeat('../', $levels) . ((is_array($var) && count($var)) ? implode('.', array_map(function($v) {
133 483
            return ($v === null) ? 'this' : "[$v]";
134 515
        }, $var)) : 'this');
135
    }
136
}
137
138