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 ( 905076...6870d0 )
by Zordius
02:17
created

Context::prepareFileExt()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

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