Complex classes like Compiler often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Compiler, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
31 | class Compiler extends Validator |
||
32 | { |
||
33 | public static $lastParsed; |
||
34 | |||
35 | /** |
||
36 | * Compile template into PHP code |
||
37 | * |
||
38 | * @param array<string,array|string|integer> $context Current context |
||
39 | * @param string $template handlebars template |
||
40 | * |
||
41 | * @return string|null generated PHP code |
||
42 | */ |
||
43 | 764 | public static function compileTemplate(&$context, $template) { |
|
74 | |||
75 | /** |
||
76 | * Compose LightnCandy render codes for include() |
||
77 | * |
||
78 | * @param array<string,array|string|integer> $context Current context |
||
79 | * @param string $code generated PHP code |
||
80 | * |
||
81 | * @return string Composed PHP code |
||
82 | */ |
||
83 | 687 | public static function composePHPRender($context, $code) { |
|
84 | 687 | $flagJStrue = Expression::boolString($context['flags']['jstrue']); |
|
85 | 687 | $flagJSObj = Expression::boolString($context['flags']['jsobj']); |
|
86 | 687 | $flagJSLen = Expression::boolString($context['flags']['jslen']); |
|
87 | 687 | $flagSPVar = Expression::boolString($context['flags']['spvar']); |
|
88 | 687 | $flagProp = Expression::boolString($context['flags']['prop']); |
|
89 | 687 | $flagMethod = Expression::boolString($context['flags']['method']); |
|
90 | 687 | $flagLambda = Expression::boolString($context['flags']['lambda']); |
|
91 | 687 | $flagMustlok = Expression::boolString($context['flags']['mustlok']); |
|
92 | 687 | $flagMustlam = Expression::boolString($context['flags']['mustlam']); |
|
93 | 687 | $flagEcho = Expression::boolString($context['flags']['echo']); |
|
94 | 687 | $flagPartNC = Expression::boolString($context['flags']['partnc']); |
|
95 | 687 | $flagKnownHlp = Expression::boolString($context['flags']['knohlp']); |
|
96 | |||
97 | 687 | $constants = Exporter::constants($context); |
|
98 | 687 | $helpers = Exporter::helpers($context); |
|
99 | 687 | $partials = implode(",\n", $context['partialCode']); |
|
100 | 687 | $debug = Runtime::DEBUG_ERROR_LOG; |
|
101 | 687 | $use = $context['flags']['standalone'] ? Exporter::runtime($context) : "use {$context['runtime']} as {$context['runtimealias']};"; |
|
102 | 687 | $safeString = (($context['usedFeature']['enc'] > 0) && ($context['flags']['standalone'] === 0)) ? "use {$context['safestring']} as SafeString;" : ''; |
|
103 | 687 | $exportSafeString = (($context['usedFeature']['enc'] > 0) && ($context['flags']['standalone'] >0)) ? Exporter::safestring($context) : ''; |
|
104 | |||
105 | // Return generated PHP code string. |
||
106 | return <<<VAREND |
||
107 | 687 | $safeString{$use}{$exportSafeString}return function (\$in = null, \$options = null) { |
|
108 | 687 | \$helpers = $helpers; |
|
109 | 687 | \$partials = array($partials); |
|
110 | \$cx = array( |
||
111 | 'flags' => array( |
||
112 | 687 | 'jstrue' => $flagJStrue, |
|
113 | 687 | 'jsobj' => $flagJSObj, |
|
114 | 687 | 'jslen' => $flagJSLen, |
|
115 | 687 | 'spvar' => $flagSPVar, |
|
116 | 687 | 'prop' => $flagProp, |
|
117 | 687 | 'method' => $flagMethod, |
|
118 | 687 | 'lambda' => $flagLambda, |
|
119 | 687 | 'mustlok' => $flagMustlok, |
|
120 | 687 | 'mustlam' => $flagMustlam, |
|
121 | 687 | 'echo' => $flagEcho, |
|
122 | 687 | 'partnc' => $flagPartNC, |
|
123 | 687 | 'knohlp' => $flagKnownHlp, |
|
124 | 687 | 'debug' => isset(\$options['debug']) ? \$options['debug'] : $debug, |
|
125 | ), |
||
126 | 687 | 'constants' => $constants, |
|
127 | 'helpers' => isset(\$options['helpers']) ? array_merge(\$helpers, \$options['helpers']) : \$helpers, |
||
128 | 'partials' => isset(\$options['partials']) ? array_merge(\$partials, \$options['partials']) : \$partials, |
||
129 | 'scopes' => array(), |
||
130 | 'sp_vars' => isset(\$options['data']) ? array_merge(array('root' => \$in), \$options['data']) : array('root' => \$in), |
||
131 | 'blparam' => array(), |
||
132 | 'partialid' => 0, |
||
133 | 687 | 'runtime' => '{$context['runtime']}', |
|
134 | ); |
||
135 | 687 | {$context['renderex']} |
|
136 | 687 | {$context['ops']['array_check']} |
|
137 | 687 | {$context['ops']['op_start']}'$code'{$context['ops']['op_end']} |
|
138 | 687 | }; |
|
139 | VAREND |
||
140 | ; |
||
141 | } |
||
142 | |||
143 | /** |
||
144 | * Get function name for standalone or none standalone template. |
||
145 | * |
||
146 | * @param array<string,array|string|integer> $context Current context of compiler progress. |
||
147 | * @param string $name base function name |
||
148 | * @param string $tag original handlabars tag for debug |
||
149 | * |
||
150 | * @return string compiled Function name |
||
151 | * |
||
152 | * @expect 'LR::test(' when input array('flags' => array('standalone' => 0, 'debug' => 0), 'runtime' => 'Runtime', 'runtimealias' => 'LR'), 'test', '' |
||
153 | * @expect 'LL::test2(' when input array('flags' => array('standalone' => 0, 'debug' => 0), 'runtime' => 'Runtime', 'runtimealias' => 'LL'), 'test2', '' |
||
154 | * @expect "lala_abctest3(" when input array('flags' => array('standalone' => 1, 'debug' => 0), 'runtime' => 'Runtime', 'runtimealias' => 0, 'funcprefix' => 'lala_abc'), 'test3', '' |
||
155 | * @expect 'RR::debug(\'abc\', \'test\', ' when input array('flags' => array('standalone' => 0, 'debug' => 1), 'runtime' => 'Runtime', 'runtimealias' => 'RR', 'funcprefix' => 'haha456'), 'test', 'abc' |
||
156 | */ |
||
157 | 622 | protected static function getFuncName(&$context, $name, $tag) { |
|
158 | 622 | static::addUsageCount($context, 'runtime', $name); |
|
159 | |||
160 | 622 | if ($context['flags']['debug'] && ($name != 'miss')) { |
|
161 | 10 | $dbg = "'$tag', '$name', "; |
|
162 | 10 | $name = 'debug'; |
|
163 | 10 | static::addUsageCount($context, 'runtime', 'debug'); |
|
164 | } else { |
||
165 | 620 | $dbg = ''; |
|
166 | } |
||
167 | |||
168 | 622 | return $context['flags']['standalone'] ? "{$context['funcprefix']}$name($dbg" : "{$context['runtimealias']}::$name($dbg"; |
|
169 | } |
||
170 | |||
171 | /** |
||
172 | * Get string presentation of variables |
||
173 | * |
||
174 | * @param array<string,array|string|integer> $context current compile context |
||
175 | * @param array<array> $vn variable name array. |
||
176 | * @param array<string>|null $blockParams block param list |
||
177 | * |
||
178 | * @return array<string|array> variable names |
||
179 | * |
||
180 | * @expect array('array(array($in),array())', array('this')) when input array('flags'=>array('spvar'=>true)), array(null) |
||
181 | * @expect array('array(array($in,$in),array())', array('this', 'this')) when input array('flags'=>array('spvar'=>true)), array(null, null) |
||
182 | * @expect array('array(array(),array(\'a\'=>$in))', array('this')) when input array('flags'=>array('spvar'=>true)), array('a' => null) |
||
183 | */ |
||
184 | 280 | protected static function getVariableNames(&$context, $vn, $blockParams = null) { |
|
185 | 280 | $vars = array(array(), array()); |
|
186 | 280 | $exps = array(); |
|
187 | 280 | foreach ($vn as $i => $v) { |
|
188 | 237 | $V = static::getVariableNameOrSubExpression($context, $v); |
|
189 | 237 | if (is_string($i)) { |
|
190 | 38 | $vars[1][] = "'$i'=>{$V[0]}"; |
|
191 | } else { |
||
192 | 222 | $vars[0][] = $V[0]; |
|
193 | } |
||
194 | 237 | $exps[] = $V[1]; |
|
195 | } |
||
196 | 280 | $bp = $blockParams ? (',array(' . Expression::listString($blockParams) . ')') : ''; |
|
197 | 280 | return array('array(array(' . implode(',', $vars[0]) . '),array(' . implode(',', $vars[1]) . ")$bp)", $exps); |
|
198 | } |
||
199 | |||
200 | /** |
||
201 | * Get string presentation of a sub expression |
||
202 | * |
||
203 | * @param array<string,array|string|integer> $context current compile context |
||
204 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
205 | * |
||
206 | * @return array<string> code representing passed expression |
||
207 | */ |
||
208 | 44 | public static function compileSubExpression(&$context, $vars) { |
|
209 | 44 | $ret = static::customHelper($context, $vars, true, true, true); |
|
210 | |||
211 | 44 | if (($ret === null) && $context['flags']['lambda']) { |
|
212 | 4 | $ret = static::compileVariable($context, $vars, true, true); |
|
213 | } |
||
214 | |||
215 | 44 | return array($ret ? $ret : '', 'FIXME: $subExpression'); |
|
216 | } |
||
217 | |||
218 | /** |
||
219 | * Get string presentation of a subexpression or a variable |
||
220 | * |
||
221 | * @param array<array|string|integer> $context current compile context |
||
222 | * @param array<array|string|integer> $var variable parsed path |
||
223 | * |
||
224 | * @return array<string> variable names |
||
|
|||
225 | */ |
||
226 | 393 | protected static function getVariableNameOrSubExpression(&$context, $var) { |
|
227 | 393 | return Parser::isSubExp($var) ? static::compileSubExpression($context, $var[1]) : static::getVariableName($context, $var); |
|
228 | } |
||
229 | |||
230 | /** |
||
231 | * Get string presentation of a variable |
||
232 | * |
||
233 | * @param array<array|string|integer> $var variable parsed path |
||
234 | * @param array<array|string|integer> $context current compile context |
||
235 | * @param array<string>|null $lookup extra lookup string as valid PHP variable name |
||
236 | * |
||
237 | * @return array<string> variable names |
||
238 | * |
||
239 | * @expect array('$in', 'this') when input array('flags'=>array('spvar'=>true,'debug'=>0)), array(null) |
||
240 | * @expect array('(($inary && isset($in[\'true\'])) ? $in[\'true\'] : null)', '[true]') when input array('flags'=>array('spvar'=>true,'debug'=>0,'prop'=>0,'method'=>0,'mustlok'=>0,'mustlam'=>0,'lambda'=>0,'jslen'=>0)), array('true') |
||
241 | * @expect array('(($inary && isset($in[\'false\'])) ? $in[\'false\'] : null)', '[false]') when input array('flags'=>array('spvar'=>true,'debug'=>0,'prop'=>0,'method'=>0,'mustlok'=>0,'mustlam'=>0,'lambda'=>0,'jslen'=>0)), array('false') |
||
242 | * @expect array('true', 'true') when input array('flags'=>array('spvar'=>true,'debug'=>0)), array(-1, 'true') |
||
243 | * @expect array('false', 'false') when input array('flags'=>array('spvar'=>true,'debug'=>0)), array(-1, 'false') |
||
244 | * @expect array('(($inary && isset($in[\'2\'])) ? $in[\'2\'] : null)', '[2]') when input array('flags'=>array('spvar'=>true,'debug'=>0,'prop'=>0,'method'=>0,'mustlok'=>0,'mustlam'=>0,'lambda'=>0,'jslen'=>0)), array('2') |
||
245 | * @expect array('2', '2') when input array('flags'=>array('spvar'=>true,'debug'=>0,'prop'=>0,'method'=>0)), array(-1, '2') |
||
246 | * @expect array('(($inary && isset($in[\'@index\'])) ? $in[\'@index\'] : null)', '[@index]') when input array('flags'=>array('spvar'=>false,'debug'=>0,'prop'=>0,'method'=>0,'mustlok'=>0,'mustlam'=>0,'lambda'=>0,'jslen'=>0)), array('@index') |
||
247 | * @expect array("(isset(\$cx['sp_vars']['index']) ? \$cx['sp_vars']['index'] : null)", '@[index]') when input array('flags'=>array('spvar'=>true,'debug'=>0,'prop'=>0,'method'=>0,'mustlok'=>0,'mustlam'=>0,'lambda'=>0,'jslen'=>0)), array('@index') |
||
248 | * @expect array("(isset(\$cx['sp_vars']['key']) ? \$cx['sp_vars']['key'] : null)", '@[key]') when input array('flags'=>array('spvar'=>true,'debug'=>0,'prop'=>0,'method'=>0,'mustlok'=>0,'mustlam'=>0,'lambda'=>0,'jslen'=>0)), array('@key') |
||
249 | * @expect array("(isset(\$cx['sp_vars']['first']) ? \$cx['sp_vars']['first'] : null)", '@[first]') when input array('flags'=>array('spvar'=>true,'debug'=>0,'prop'=>0,'method'=>0,'mustlok'=>0,'mustlam'=>0,'lambda'=>0,'jslen'=>0)), array('@first') |
||
250 | * @expect array("(isset(\$cx['sp_vars']['last']) ? \$cx['sp_vars']['last'] : null)", '@[last]') when input array('flags'=>array('spvar'=>true,'debug'=>0,'prop'=>0,'method'=>0,'mustlok'=>0,'mustlam'=>0,'lambda'=>0,'jslen'=>0)), array('@last') |
||
251 | * @expect array('(($inary && isset($in[\'"a"\'])) ? $in[\'"a"\'] : null)', '["a"]') when input array('flags'=>array('spvar'=>true,'debug'=>0,'prop'=>0,'method'=>0,'mustlok'=>0,'mustlam'=>0,'lambda'=>0,'jslen'=>0)), array('"a"') |
||
252 | * @expect array('"a"', '"a"') when input array('flags'=>array('spvar'=>true,'debug'=>0)), array(-1, '"a"') |
||
253 | * @expect array('(($inary && isset($in[\'a\'])) ? $in[\'a\'] : null)', '[a]') when input array('flags'=>array('spvar'=>true,'debug'=>0,'prop'=>0,'method'=>0,'mustlok'=>0,'mustlam'=>0,'lambda'=>0,'jslen'=>0)), array('a') |
||
254 | * @expect array('((isset($cx[\'scopes\'][count($cx[\'scopes\'])-1]) && is_array($cx[\'scopes\'][count($cx[\'scopes\'])-1]) && isset($cx[\'scopes\'][count($cx[\'scopes\'])-1][\'a\'])) ? $cx[\'scopes\'][count($cx[\'scopes\'])-1][\'a\'] : null)', '../[a]') when input array('flags'=>array('spvar'=>true,'debug'=>0,'prop'=>0,'method'=>0,'mustlok'=>0,'mustlam'=>0,'lambda'=>0,'jslen'=>0)), array(1,'a') |
||
255 | * @expect array('((isset($cx[\'scopes\'][count($cx[\'scopes\'])-3]) && is_array($cx[\'scopes\'][count($cx[\'scopes\'])-3]) && isset($cx[\'scopes\'][count($cx[\'scopes\'])-3][\'a\'])) ? $cx[\'scopes\'][count($cx[\'scopes\'])-3][\'a\'] : null)', '../../../[a]') when input array('flags'=>array('spvar'=>true,'debug'=>0,'prop'=>0,'method'=>0,'mustlok'=>0,'mustlam'=>0,'lambda'=>0,'jslen'=>0)), array(3,'a') |
||
256 | * @expect array('(($inary && isset($in[\'id\'])) ? $in[\'id\'] : null)', 'this.[id]') when input array('flags'=>array('spvar'=>true,'debug'=>0,'prop'=>0,'method'=>0,'mustlok'=>0,'mustlam'=>0,'lambda'=>0,'jslen'=>0)), array(null, 'id') |
||
257 | * @expect array('LR::v($cx, $in, isset($in) ? $in : null, array(\'id\'))', 'this.[id]') when input array('flags'=>array('prop'=>true,'spvar'=>true,'debug'=>0,'method'=>0,'mustlok'=>0,'mustlam'=>0,'lambda'=>0,'jslen'=>0,'standalone'=>0), 'runtime' => 'Runtime', 'runtimealias' => 'LR'), array(null, 'id') |
||
258 | */ |
||
259 | 614 | protected static function getVariableName(&$context, $var, $lookup = null, $args = null) { |
|
260 | 614 | if (isset($var[0]) && ($var[0] === Parser::LITERAL)) { |
|
261 | 89 | if ($var[1] === "undefined") { |
|
262 | 2 | $var[1] = "null"; |
|
263 | } |
||
264 | 89 | return array($var[1], preg_replace('/\'(.*)\'/', '$1', $var[1])); |
|
265 | } |
||
266 | |||
267 | 572 | list($levels, $spvar, $var) = Expression::analyze($context, $var); |
|
268 | 572 | $exp = Expression::toString($levels, $spvar, $var); |
|
269 | 572 | $base = $spvar ? "\$cx['sp_vars']" : '$in'; |
|
270 | |||
271 | // change base when trace to parent |
||
272 | 572 | if ($levels > 0) { |
|
273 | 41 | if ($spvar) { |
|
274 | 2 | $base .= str_repeat("['_parent']", $levels); |
|
275 | } else { |
||
276 | 39 | $base = "\$cx['scopes'][count(\$cx['scopes'])-$levels]"; |
|
277 | } |
||
278 | } |
||
279 | |||
280 | 572 | if (((count($var) == 0) || (($var[0] === null) && (count($var) == 1))) && ($lookup === null)) { |
|
281 | 148 | return array($base, $exp); |
|
282 | } |
||
283 | |||
284 | 511 | if ((count($var) > 0) && ($var[0] === null)) { |
|
285 | 1 | array_shift($var); |
|
286 | } |
||
287 | |||
288 | // To support recursive context lookup, instance properties + methods and lambdas |
||
289 | // the only way is using slower rendering time variable resolver. |
||
290 | 511 | if ($context['flags']['prop'] || $context['flags']['method'] || $context['flags']['mustlok'] || $context['flags']['mustlam'] || $context['flags']['lambda']) { |
|
291 | 387 | $L = Expression::listString($var); |
|
292 | 387 | $L = ($L === '') ? array() : array($L); |
|
293 | 387 | if ($lookup) { |
|
294 | 3 | $L[] = $lookup[0]; |
|
295 | } |
||
296 | 387 | $A = $args ? ",$args[0]" : ''; |
|
297 | 387 | $E = $args ? ' ' . implode(' ', $args[1]) : ''; |
|
298 | 387 | return array(static::getFuncName($context, 'v', $exp) . "\$cx, \$in, isset($base) ? $base : null, array(" . implode($L, ',') . ")$A)", $lookup ? "lookup $exp $lookup[1]" : "$exp$E"); |
|
299 | } |
||
300 | |||
301 | 125 | $n = Expression::arrayString($var); |
|
302 | 125 | $k = array_pop($var); |
|
303 | 125 | $L = $lookup ? "[{$lookup[0]}]" : ''; |
|
304 | 125 | $p = $lookup ? $n : (count($var) ? Expression::arrayString($var) : ''); |
|
305 | |||
306 | 125 | $checks = array(); |
|
307 | 125 | if ($levels > 0) { |
|
308 | 11 | $checks[] = "isset($base)"; |
|
309 | } |
||
310 | 125 | if (!$spvar) { |
|
311 | 121 | if (($levels === 0) && $p) { |
|
312 | 14 | $checks[] = "isset($base$p)"; |
|
313 | } |
||
314 | 121 | $checks[] = ("$base$p" == '$in') ? '$inary' : "is_array($base$p)"; |
|
315 | } |
||
316 | 125 | $checks[] = "isset($base$n$L)"; |
|
317 | 125 | $check = ((count($checks) > 1) ? '(' : '') . implode(' && ', $checks) . ((count($checks) > 1) ? ')' : ''); |
|
318 | |||
319 | 125 | $lenStart = ''; |
|
320 | 125 | $lenEnd = ''; |
|
321 | |||
322 | 125 | if ($context['flags']['jslen']) { |
|
323 | 50 | if (($lookup === null) && ($k === 'length')) { |
|
324 | 1 | array_pop($checks); |
|
325 | 1 | $lenStart = '(' . ((count($checks) > 1) ? '(' : '') . implode(' && ', $checks) . ((count($checks) > 1) ? ')' : '') . " ? count($base" . Expression::arrayString($var) . ') : '; |
|
326 | 1 | $lenEnd = ')'; |
|
327 | } |
||
328 | } |
||
329 | |||
330 | 125 | return array("($check ? $base$n$L : $lenStart" . ($context['flags']['debug'] ? (static::getFuncName($context, 'miss', '') . "\$cx, '$exp')") : 'null' ) . ")$lenEnd", $lookup ? "lookup $exp $lookup[1]" : $exp); |
|
331 | } |
||
332 | |||
333 | /** |
||
334 | * Return compiled PHP code for a handlebars token |
||
335 | * |
||
336 | * @param array<string,array|string|integer> $context current compile context |
||
337 | * @param array<string,array|boolean> $info parsed information |
||
338 | * |
||
339 | * @return string Return compiled code segment for the token |
||
340 | */ |
||
341 | 647 | protected static function compileToken(&$context, $info) { |
|
368 | |||
369 | /** |
||
370 | * handle partial |
||
371 | * |
||
372 | * @param array<string,array|string|integer> $context current compile context |
||
373 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
374 | * |
||
375 | * @return string Return compiled code segment for the partial |
||
376 | */ |
||
377 | 97 | public static function partial(&$context, $vars) { |
|
397 | |||
398 | /** |
||
399 | * handle inline partial |
||
400 | * |
||
401 | * @param array<string,array|string|integer> $context current compile context |
||
402 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
403 | * |
||
404 | * @return string Return compiled code segment for the partial |
||
405 | */ |
||
406 | 11 | public static function inline(&$context, $vars) { |
|
417 | |||
418 | /** |
||
419 | * Return compiled PHP code for a handlebars inverted section begin token |
||
420 | * |
||
421 | * @param array<string,array|string|integer> $context current compile context |
||
422 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
423 | * |
||
424 | * @return string Return compiled code segment for the token |
||
425 | */ |
||
426 | 38 | protected static function invertedSection(&$context, $vars) { |
|
430 | |||
431 | /** |
||
432 | * Return compiled PHP code for a handlebars block custom helper begin token |
||
433 | * |
||
434 | * @param array<string,array|string|integer> $context current compile context |
||
435 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
436 | * @param boolean $inverted the logic will be inverted |
||
437 | * |
||
438 | * @return string Return compiled code segment for the token |
||
439 | */ |
||
440 | 63 | protected static function blockCustomHelper(&$context, $vars, $inverted = false) { |
|
449 | |||
450 | /** |
||
451 | * Return compiled PHP code for a handlebars block end token |
||
452 | * |
||
453 | * @param array<string,array|string|integer> $context current compile context |
||
454 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
455 | * @param string|null $matchop should also match to this operator |
||
456 | * |
||
457 | * @return string Return compiled code segment for the token |
||
458 | */ |
||
459 | 333 | protected static function blockEnd(&$context, &$vars, $matchop = NULL) { |
|
491 | |||
492 | /** |
||
493 | * Return compiled PHP code for a handlebars block begin token |
||
494 | * |
||
495 | * @param array<string,array|string|integer> $context current compile context |
||
496 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
497 | * |
||
498 | * @return string Return compiled code segment for the token |
||
499 | */ |
||
500 | 249 | protected static function blockBegin(&$context, $vars) { |
|
520 | |||
521 | /** |
||
522 | * compile {{#foo}} token |
||
523 | * |
||
524 | * @param array<string,array|string|integer> $context current compile context |
||
525 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
526 | * @param boolean $isEach the section is #each |
||
527 | * |
||
528 | * @return string|null Return compiled code segment for the token |
||
529 | */ |
||
530 | 167 | protected static function section(&$context, $vars, $isEach = false) { |
|
548 | |||
549 | /** |
||
550 | * compile {{with}} token |
||
551 | * |
||
552 | * @param array<string,array|string|integer> $context current compile context |
||
553 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
554 | * |
||
555 | * @return string|null Return compiled code segment for the token |
||
556 | */ |
||
557 | 30 | protected static function with(&$context, $vars) { |
|
564 | |||
565 | /** |
||
566 | * Return compiled PHP code for a handlebars custom helper token |
||
567 | * |
||
568 | * @param array<string,array|string|integer> $context current compile context |
||
569 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
570 | * @param boolean $raw is this {{{ token or not |
||
571 | * @param boolean $nosep true to compile without seperator |
||
572 | * @param boolean $subExp true when compile for subexpression |
||
573 | * |
||
574 | * @return string|null Return compiled code segment for the token when the token is custom helper |
||
575 | */ |
||
576 | 480 | protected static function customHelper(&$context, $vars, $raw, $nosep, $subExp = false) { |
|
598 | |||
599 | /** |
||
600 | * Return compiled PHP code for a handlebars else token |
||
601 | * |
||
602 | * @param array<string,array|string|integer> $context current compile context |
||
603 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
604 | * |
||
605 | * @return string Return compiled code segment for the token when the token is else |
||
606 | */ |
||
607 | 57 | protected static function doElse(&$context, $vars) { |
|
618 | |||
619 | /** |
||
620 | * Return compiled PHP code for a handlebars log token |
||
621 | * |
||
622 | * @param array<string,array|string|integer> $context current compile context |
||
623 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
624 | * @param boolean $raw is this {{{ token or not |
||
625 | * |
||
626 | * @return string Return compiled code segment for the token |
||
627 | */ |
||
628 | 2 | protected static function compileLog(&$context, &$vars, $raw) { |
|
633 | |||
634 | /** |
||
635 | * Return compiled PHP code for a handlebars lookup token |
||
636 | * |
||
637 | * @param array<string,array|string|integer> $context current compile context |
||
638 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
639 | * @param boolean $raw is this {{{ token or not |
||
640 | * @param boolean $nosep true to compile without seperator |
||
641 | * |
||
642 | * @return string Return compiled code segment for the token |
||
643 | */ |
||
644 | 7 | protected static function compileLookup(&$context, &$vars, $raw, $nosep = false) { |
|
656 | |||
657 | /** |
||
658 | * Return compiled PHP code for template output |
||
659 | * |
||
660 | * @param array<string,array|string|integer> $context current compile context |
||
661 | * @param string $variable PHP code for the variable |
||
662 | * @param string $expression normalized handlebars expression |
||
663 | * @param boolean $raw is this {{{ token or not |
||
664 | * @param boolean $nosep true to compile without seperator |
||
665 | * |
||
666 | * @return string Return compiled code segment for the token |
||
667 | */ |
||
668 | 480 | protected static function compileOutput(&$context, $variable, $expression, $raw, $nosep) { |
|
676 | |||
677 | /** |
||
678 | * Return compiled PHP code for a handlebars variable token |
||
679 | * |
||
680 | * @param array<string,array|string|integer> $context current compile context |
||
681 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
682 | * @param boolean $raw is this {{{ token or not |
||
683 | * @param boolean $nosep true to compile without seperator |
||
684 | * |
||
685 | * @return string Return compiled code segment for the token |
||
686 | */ |
||
687 | 372 | protected static function compileVariable(&$context, &$vars, $raw, $nosep) { |
|
696 | |||
697 | /** |
||
698 | * Add usage count to context |
||
699 | * |
||
700 | * @param array<string,array|string|integer> $context current context |
||
701 | * @param string $category category name, can be one of: 'var', 'helpers', 'runtime' |
||
702 | * @param string $name used name |
||
703 | * @param integer $count increment |
||
704 | * |
||
705 | * @expect 1 when input array('usedCount' => array('test' => array())), 'test', 'testname' |
||
706 | * @expect 3 when input array('usedCount' => array('test' => array('testname' => 2))), 'test', 'testname' |
||
707 | * @expect 5 when input array('usedCount' => array('test' => array('testname' => 2))), 'test', 'testname', 3 |
||
708 | */ |
||
709 | 622 | protected static function addUsageCount(&$context, $category, $name, $count = 1) { |
|
715 | } |
||
716 | |||
717 |
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.