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 ( 4d68fd...6b2287 )
by Zordius
03:13
created

Context   A

Complexity

Total Complexity 29

Size/Duplication

Total Lines 210
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 29
lcom 0
cbo 1
dl 0
loc 210
ccs 81
cts 81
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
C updateHelperTable() 0 22 8
A merge() 0 10 1
F create() 0 145 20
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-2016 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 to handle LightnCandy Context
16
 *
17
 * @package    LightnCandy
18
 * @author     Zordius <[email protected]>
19
 */
20
21
namespace LightnCandy;
22
23
use \LightnCandy\Flags;
24
25
/**
26
 * LightnCandy class to handle Context
27
 */
28
class Context extends Flags
29
{
30
    /**
31
     * Create a context from options
32
     *
33
     * @param array<string,array|string|integer> $options input options
34
     *
35
     * @return array<string,array|string|integer> Context from options
36
     */
37 768
    public static function create($options) {
38 768
        if (!is_array($options)) {
39 7
            $options = array();
40
        }
41
42 768
        $flags = isset($options['flags']) ? $options['flags'] : static::FLAG_BESTPERFORMANCE;
43
44
        $context = array(
45
            'flags' => array(
46 768
                'errorlog' => $flags & static::FLAG_ERROR_LOG,
47 768
                'exception' => $flags & static::FLAG_ERROR_EXCEPTION,
48 768
                'skippartial' => $flags & static::FLAG_ERROR_SKIPPARTIAL,
49 768
                'standalone' => $flags & static::FLAG_STANDALONEPHP,
50 768
                'noesc' => $flags & static::FLAG_NOESCAPE,
51 768
                'jstrue' => $flags & static::FLAG_JSTRUE,
52 768
                'jsobj' => $flags & static::FLAG_JSOBJECT,
53 768
                'jslen' => $flags & static::FLAG_JSLENGTH,
54 768
                'hbesc' => $flags & static::FLAG_HBESCAPE,
55 768
                'this' => $flags & static::FLAG_THIS,
56 768
                'nohbh' => $flags & static::FLAG_NOHBHELPERS,
57 768
                'parent' => $flags & static::FLAG_PARENT,
58 768
                'echo' => $flags & static::FLAG_ECHO,
59 768
                'advar' => $flags & static::FLAG_ADVARNAME,
60 768
                'namev' => $flags & static::FLAG_NAMEDARG,
61 768
                'spvar' => $flags & static::FLAG_SPVARS,
62 768
                'slash' => $flags & static::FLAG_SLASH,
63 768
                'else' => $flags & static::FLAG_ELSE,
64 768
                'exhlp' => $flags & static::FLAG_EXTHELPER,
65 768
                'lambda' => $flags & static::FLAG_HANDLEBARSLAMBDA,
66 768
                'mustlok' => $flags & static::FLAG_MUSTACHELOOKUP,
67 768
                'mustlam' => $flags & static::FLAG_MUSTACHELAMBDA,
68 768
                'mustsec' => $flags & static::FLAG_MUSTACHESECTION,
69 768
                'noind' => $flags & static::FLAG_PREVENTINDENT,
70 768
                'debug' => $flags & static::FLAG_RENDER_DEBUG,
71 768
                'prop' => $flags & static::FLAG_PROPERTY,
72 768
                'method' => $flags & static::FLAG_METHOD,
73 768
                'runpart' => $flags & static::FLAG_RUNTIMEPARTIAL,
74 768
                'rawblock' => $flags & static::FLAG_RAWBLOCK,
75 768
                'partnc' => $flags & static::FLAG_PARTIALNEWCONTEXT,
76 768
                'nostd' => $flags & static::FLAG_IGNORESTANDALONE,
77 768
                'strpar' => $flags & static::FLAG_STRINGPARAMS,
78 768
                'knohlp' => $flags & static::FLAG_KNOWNHELPERSONLY,
79 768
            ),
80
            'delimiters' => array(
81 768
                isset($options['delimiters'][0]) ? $options['delimiters'][0] : '{{',
82 768
                isset($options['delimiters'][1]) ? $options['delimiters'][1] : '}}',
83
            ),
84 768
            'level' => 0,
85
            'stack' => array(),
86
            'currentToken' => null,
87
            'error' => array(),
88
            'elselvl' => array(),
89
            'elsechain' => false,
90
            'tokens' => array(
91
                'standalone' => true,
92
                'ahead' => false,
93
                'current' => 0,
94
                'count' => 0,
95
                'partialind' => '',
96
            ),
97
            'usedPartial' => array(),
98
            'partialStack' => array(),
99
            'partialCode' => array(),
100
            'usedFeature' => array(
101
                'rootthis' => 0,
102
                'enc' => 0,
103
                'raw' => 0,
104
                'sec' => 0,
105
                'isec' => 0,
106
                'if' => 0,
107
                'else' => 0,
108
                'unless' => 0,
109
                'each' => 0,
110
                'this' => 0,
111
                'parent' => 0,
112
                'with' => 0,
113
                'comment' => 0,
114
                'partial' => 0,
115
                'dynpartial' => 0,
116
                'inlpartial' => 0,
117
                'helper' => 0,
118
                'delimiter' => 0,
119
                'subexp' => 0,
120
                'rawblock' => 0,
121
                'pblock' => 0,
122
                'lookup' => 0,
123
                'log' => 0,
124
            ),
125
            'usedCount' => array(
126
                'var' => array(),
127
                'helpers' => array(),
128
                'runtime' => array(),
129
            ),
130
            'compile' => false,
131
            'parsed' => array(),
132 768
            'partials' => (isset($options['partials']) && is_array($options['partials'])) ? $options['partials'] : array(),
133
            'partialblock' => array(),
134
            'inlinepartial' => array(),
135
            'helpers' => array(),
136 768
            'renderex' => isset($options['renderex']) ? $options['renderex'] : '',
137 768
            'prepartial' => (isset($options['prepartial']) && is_callable($options['prepartial'])) ? $options['prepartial'] : false,
138 768
            'helperresolver' => (isset($options['helperresolver']) && is_callable($options['helperresolver'])) ? $options['helperresolver'] : false,
139 768
            'partialresolver' => (isset($options['partialresolver']) && is_callable($options['partialresolver'])) ? $options['partialresolver'] : false,
140 768
            'runtime' => isset($options['runtime']) ? $options['runtime'] : '\\LightnCandy\\Runtime',
141 768
            'runtimealias' => 'LR',
142 768
            'safestring' => '\\LightnCandy\\SafeString',
143 768
            'safestringalias' => isset($options['safestring']) ? $options['safestring'] : 'LS',
144
            'rawblock' => false,
145 768
            'funcprefix' => uniqid('lcr'),
146
        );
147
148 768
        $context['ops'] = $context['flags']['echo'] ? array(
149 23
            'seperator' => ',',
150
            'f_start' => 'echo ',
151
            'f_end' => ';',
152
            'op_start' => 'ob_start();echo ',
153
            'op_end' => ';return ob_get_clean();',
154
            'cnd_start' => ';if ',
155
            'cnd_then' => '{echo ',
156
            'cnd_else' => ';}else{echo ',
157
            'cnd_end' => ';}echo ',
158
            'cnd_nend' => ';}',
159
        ) : array(
160 745
            'seperator' => '.',
161
            'f_start' => 'return ',
162
            'f_end' => ';',
163
            'op_start' => 'return ',
164
            'op_end' => ';',
165
            'cnd_start' => '.(',
166
            'cnd_then' => ' ? ',
167
            'cnd_else' => ' : ',
168
            'cnd_end' => ').',
169
            'cnd_nend' => ')',
170
        );
171
172 768
        $context['ops']['enc'] = $context['flags']['hbesc'] ? 'encq' : 'enc';
173 768
        $context['ops']['array_check'] = '$inary=is_array($in);';
174 768
        static::updateHelperTable($context, $options);
175
176 768
        if ($context['flags']['partnc'] && ($context['flags']['runpart'] == 0)) {
177
            $context['error'][] = 'The FLAG_PARTIALNEWCONTEXT requires FLAG_RUNTIMEPARTIAL! Fix your compile options please';
178
        }
179
180 768
        return $context;
181
    }
182
183
    /**
184
     * update specific custom helper table from options
185
     *
186
     * @param array<string,array|string|integer> $context prepared context
187
     * @param array<string,array|string|integer> $options input options
188
     * @param string $tname helper table name
189
     *
190
     * @return array<string,array|string|integer> context with generated helper table
191
     *
192
     * @expect array() when input array(), array()
193
     * @expect array('flags' => array('exhlp' => 1), 'helpers' => array('abc' => 1)) when input array('flags' => array('exhlp' => 1)), array('helpers' => array('abc'))
194
     * @expect array('error' => array('You provide a custom helper named as \'abc\' in options[\'helpers\'], but the function abc() is not defined!'), 'flags' => array('exhlp' => 0)) when input array('error' => array(), 'flags' => array('exhlp' => 0)), array('helpers' => array('abc'))
195
     * @expect array('flags' => array('exhlp' => 1), 'helpers' => array('\\LightnCandy\\Runtime::raw' => '\\LightnCandy\\Runtime::raw')) when input array('flags' => array('exhlp' => 1), 'helpers' => array()), array('helpers' => array('\\LightnCandy\\Runtime::raw'))
196
     * @expect array('flags' => array('exhlp' => 1), 'helpers' => array('test' => '\\LightnCandy\\Runtime::raw')) when input array('flags' => array('exhlp' => 1), 'helpers' => array()), array('helpers' => array('test' => '\\LightnCandy\\Runtime::raw'))
197
     */
198 769
    protected static function updateHelperTable(&$context, $options, $tname = 'helpers') {
199 769
        if (isset($options[$tname]) && is_array($options[$tname])) {
200 465
            foreach ($options[$tname] as $name => $func) {
201 204
                $tn = is_int($name) ? $func : $name;
202 204
                if (is_callable($func)) {
203 202
                    $context[$tname][$tn] = $func;
204
                } else {
205 4
                    if (is_array($func)) {
206 1
                        $context['error'][] = "I found an array in $tname with key as $name, please fix it.";
207
                    } else {
208 3
                        if ($context['flags']['exhlp']) {
209
                            // Regist helper names only
210 2
                            $context[$tname][$tn] = 1;
211
                        } else {
212 204
                            $context['error'][] = "You provide a custom helper named as '$tn' in options['$tname'], but the function $func() is not defined!";
213
                        }
214
                    }
215
                }
216
            }
217
        }
218 769
        return $context;
219
    }
220
221
    /**
222
     * Merge a context into another
223
     *
224
     * @param array<string,array|string|integer> $context master context
225
     * @param array<string,array|string|integer> $tmp another context will be overwrited into master context
226
     */
227 88
    public static function merge(&$context, $tmp) {
228 88
        $context['error'] = $tmp['error'];
229 88
        $context['helpers'] = $tmp['helpers'];
230 88
        $context['partials'] = $tmp['partials'];
231 88
        $context['partialCode'] = $tmp['partialCode'];
232 88
        $context['partialStack'] = $tmp['partialStack'];
233 88
        $context['usedCount'] = $tmp['usedCount'];
234 88
        $context['usedFeature'] = $tmp['usedFeature'];
235 88
        $context['usedPartial'] = $tmp['usedPartial'];
236 88
    }
237
}
238
239