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 | 734 | public static function compileTemplate(&$context, $template) { |
|
| 44 | 734 | array_unshift($context['parsed'], array()); |
|
| 45 | 734 | Validator::verify($context, $template); |
|
| 46 | |||
| 47 | 734 | if (count($context['error'])) { |
|
| 48 | 75 | return; |
|
| 49 | } |
||
| 50 | |||
| 51 | 660 | Parser::setDelimiter($context); |
|
| 52 | |||
| 53 | 660 | $context['compile'] = true; |
|
| 54 | |||
| 55 | // Handle dynamic partials |
||
| 56 | 660 | Partial::handleDynamic($context); |
|
| 57 | |||
| 58 | // Do PHP code generation. |
||
| 59 | 660 | $code = ''; |
|
| 60 | 660 | foreach ($context['parsed'][0] as $info) { |
|
| 61 | 660 | if (is_array($info)) { |
|
| 62 | 619 | $context['tokens']['current']++; |
|
| 63 | 619 | $code .= "'" . static::compileToken($context, $info) . "'"; |
|
| 64 | } else { |
||
| 65 | 660 | $code .= $info; |
|
| 66 | } |
||
| 67 | } |
||
| 68 | |||
| 69 | 660 | static::$lastParsed = array_shift($context['parsed']); |
|
| 70 | |||
| 71 | 660 | return $code; |
|
| 72 | } |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Compose LightnCandy render codes for include() |
||
| 76 | * |
||
| 77 | * @param array<string,array|string|integer> $context Current context |
||
| 78 | * @param string $code generated PHP code |
||
| 79 | * |
||
| 80 | * @return string Composed PHP code |
||
| 81 | */ |
||
| 82 | 659 | public static function composePHPRender($context, $code) { |
|
| 83 | 659 | $flagJStrue = Expression::boolString($context['flags']['jstrue']); |
|
| 84 | 659 | $flagJSObj = Expression::boolString($context['flags']['jsobj']); |
|
| 85 | 659 | $flagSPVar = Expression::boolString($context['flags']['spvar']); |
|
| 86 | 659 | $flagProp = Expression::boolString($context['flags']['prop']); |
|
| 87 | 659 | $flagMethod = Expression::boolString($context['flags']['method']); |
|
| 88 | 659 | $flagLambda = Expression::boolString($context['flags']['lambda']); |
|
| 89 | 659 | $flagMustlok = Expression::boolString($context['flags']['mustlok']); |
|
| 90 | 659 | $flagMustlam = Expression::boolString($context['flags']['mustlam']); |
|
| 91 | 659 | $flagEcho = Expression::boolString($context['flags']['echo']); |
|
| 92 | 659 | $flagPartNC = Expression::boolString($context['flags']['partnc']); |
|
| 93 | 659 | $flagKnownHlp = Expression::boolString($context['flags']['knohlp']); |
|
| 94 | |||
| 95 | 659 | $constants = Exporter::constants($context); |
|
| 96 | 659 | $helpers = Exporter::helpers($context); |
|
| 97 | 659 | $partials = implode(",\n", $context['partialCode']); |
|
| 98 | 659 | $debug = Runtime::DEBUG_ERROR_LOG; |
|
| 99 | 659 | $use = $context['flags']['standalone'] ? Exporter::runtime($context) : "use {$context['runtime']} as {$context['runtimealias']};"; |
|
| 100 | 659 | $safeString = (($context['usedFeature']['enc'] > 0) && ($context['flags']['standalone'] === 0)) ? "use {$context['safestring']} as SafeString;" : ''; |
|
| 101 | 659 | $exportSafeString = (($context['usedFeature']['enc'] > 0) && ($context['flags']['standalone'] >0)) ? Exporter::safestring($context) : ''; |
|
| 102 | |||
| 103 | // Return generated PHP code string. |
||
| 104 | return <<<VAREND |
||
| 105 | 659 | $safeString{$use}{$exportSafeString}return function (\$in = null, \$options = null) { |
|
| 106 | 659 | \$helpers = $helpers; |
|
| 107 | 659 | \$partials = array($partials); |
|
| 108 | \$cx = array( |
||
| 109 | 'flags' => array( |
||
| 110 | 659 | 'jstrue' => $flagJStrue, |
|
| 111 | 659 | 'jsobj' => $flagJSObj, |
|
| 112 | 659 | 'spvar' => $flagSPVar, |
|
| 113 | 659 | 'prop' => $flagProp, |
|
| 114 | 659 | 'method' => $flagMethod, |
|
| 115 | 659 | 'lambda' => $flagLambda, |
|
| 116 | 659 | 'mustlok' => $flagMustlok, |
|
| 117 | 659 | 'mustlam' => $flagMustlam, |
|
| 118 | 659 | 'echo' => $flagEcho, |
|
| 119 | 659 | 'partnc' => $flagPartNC, |
|
| 120 | 659 | 'knohlp' => $flagKnownHlp, |
|
| 121 | 659 | 'debug' => isset(\$options['debug']) ? \$options['debug'] : $debug, |
|
| 122 | ), |
||
| 123 | 659 | 'constants' => $constants, |
|
| 124 | 'helpers' => isset(\$options['helpers']) ? array_merge(\$helpers, \$options['helpers']) : \$helpers, |
||
| 125 | 'partials' => isset(\$options['partials']) ? array_merge(\$partials, \$options['partials']) : \$partials, |
||
| 126 | 'scopes' => array(), |
||
| 127 | 'sp_vars' => isset(\$options['data']) ? array_merge(array('root' => \$in), \$options['data']) : array('root' => \$in), |
||
| 128 | 'blparam' => array(), |
||
| 129 | 'partialid' => 0, |
||
| 130 | 659 | 'runtime' => '{$context['runtime']}', |
|
| 131 | ); |
||
| 132 | 659 | {$context['renderex']} |
|
| 133 | 659 | {$context['ops']['op_start']}'$code'{$context['ops']['op_end']} |
|
| 134 | 659 | }; |
|
| 135 | VAREND |
||
| 136 | ; |
||
| 137 | } |
||
| 138 | |||
| 139 | /** |
||
| 140 | * Get function name for standalone or none standalone template. |
||
| 141 | * |
||
| 142 | * @param array<string,array|string|integer> $context Current context of compiler progress. |
||
| 143 | * @param string $name base function name |
||
| 144 | * @param string $tag original handlabars tag for debug |
||
| 145 | * |
||
| 146 | * @return string compiled Function name |
||
| 147 | * |
||
| 148 | * @expect 'LR::test(' when input array('flags' => array('standalone' => 0, 'debug' => 0), 'runtime' => 'Runtime', 'runtimealias' => 'LR'), 'test', '' |
||
| 149 | * @expect 'LL::test2(' when input array('flags' => array('standalone' => 0, 'debug' => 0), 'runtime' => 'Runtime', 'runtimealias' => 'LL'), 'test2', '' |
||
| 150 | * @expect "lala_abctest3(" when input array('flags' => array('standalone' => 1, 'debug' => 0), 'runtime' => 'Runtime', 'runtimealias' => 0, 'funcprefix' => 'lala_abc'), 'test3', '' |
||
| 151 | * @expect 'RR::debug(\'abc\', \'test\', ' when input array('flags' => array('standalone' => 0, 'debug' => 1), 'runtime' => 'Runtime', 'runtimealias' => 'RR', 'funcprefix' => 'haha456'), 'test', 'abc' |
||
| 152 | */ |
||
| 153 | 594 | protected static function getFuncName(&$context, $name, $tag) { |
|
| 166 | |||
| 167 | /** |
||
| 168 | * Get string presentation of variables |
||
| 169 | * |
||
| 170 | * @param array<string,array|string|integer> $context current compile context |
||
| 171 | * @param array<array> $vn variable name array. |
||
| 172 | * @param array<string>|null $blockParams block param list |
||
| 173 | * |
||
| 174 | * @return array<string|array> variable names |
||
| 175 | * |
||
| 176 | * @expect array('array(array($in),array())', array('this')) when input array('flags'=>array('spvar'=>true)), array(null) |
||
| 177 | * @expect array('array(array($in,$in),array())', array('this', 'this')) when input array('flags'=>array('spvar'=>true)), array(null, null) |
||
| 178 | * @expect array('array(array(),array(\'a\'=>$in))', array('this')) when input array('flags'=>array('spvar'=>true)), array('a' => null) |
||
| 179 | */ |
||
| 180 | 262 | protected static function getVariableNames(&$context, $vn, $blockParams = null) { |
|
| 181 | 262 | $vars = array(array(), array()); |
|
| 182 | 262 | $exps = array(); |
|
| 183 | 262 | foreach ($vn as $i => $v) { |
|
| 184 | 224 | $V = static::getVariableNameOrSubExpression($context, $v); |
|
| 185 | 224 | if (is_string($i)) { |
|
| 186 | 37 | $vars[1][] = "'$i'=>{$V[0]}"; |
|
| 187 | } else { |
||
| 188 | 210 | $vars[0][] = $V[0]; |
|
| 189 | } |
||
| 190 | 224 | $exps[] = $V[1]; |
|
| 191 | } |
||
| 192 | 262 | $bp = $blockParams ? (',array(' . Expression::listString($blockParams) . ')') : ''; |
|
| 193 | 262 | return array('array(array(' . implode(',', $vars[0]) . '),array(' . implode(',', $vars[1]) . ")$bp)", $exps); |
|
| 194 | } |
||
| 195 | |||
| 196 | /** |
||
| 197 | * Get string presentation of a sub expression |
||
| 198 | * |
||
| 199 | * @param array<string,array|string|integer> $context current compile context |
||
| 200 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 201 | * |
||
| 202 | * @return array<string> code representing passed expression |
||
| 203 | */ |
||
| 204 | 41 | public static function compileSubExpression(&$context, $vars) { |
|
| 213 | |||
| 214 | /** |
||
| 215 | * Get string presentation of a subexpression or a variable |
||
| 216 | * |
||
| 217 | * @param array<array|string|integer> $context current compile context |
||
| 218 | * @param array<array|string|integer> $var variable parsed path |
||
| 219 | * |
||
| 220 | * @return array<string> variable names |
||
|
|
|||
| 221 | */ |
||
| 222 | 373 | protected static function getVariableNameOrSubExpression(&$context, $var) { |
|
| 225 | |||
| 226 | /** |
||
| 227 | * Get string presentation of a variable |
||
| 228 | * |
||
| 229 | * @param array<array|string|integer> $var variable parsed path |
||
| 230 | * @param array<array|string|integer> $context current compile context |
||
| 231 | * @param array<string>|null $lookup extra lookup string as valid PHP variable name |
||
| 232 | * |
||
| 233 | * @return array<string> variable names |
||
| 234 | * |
||
| 235 | * @expect array('$in', 'this') when input array('flags'=>array('spvar'=>true,'debug'=>0)), array(null) |
||
| 236 | * @expect array('((is_array($in) && 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') |
||
| 237 | * @expect array('((is_array($in) && 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') |
||
| 238 | * @expect array('true', 'true') when input array('flags'=>array('spvar'=>true,'debug'=>0)), array(-1, 'true') |
||
| 239 | * @expect array('false', 'false') when input array('flags'=>array('spvar'=>true,'debug'=>0)), array(-1, 'false') |
||
| 240 | * @expect array('((is_array($in) && 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') |
||
| 241 | * @expect array('2', '2') when input array('flags'=>array('spvar'=>true,'debug'=>0,'prop'=>0,'method'=>0)), array(-1, '2') |
||
| 242 | * @expect array('((is_array($in) && 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') |
||
| 243 | * @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') |
||
| 244 | * @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') |
||
| 245 | * @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') |
||
| 246 | * @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') |
||
| 247 | * @expect array('((is_array($in) && 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"') |
||
| 248 | * @expect array('"a"', '"a"') when input array('flags'=>array('spvar'=>true,'debug'=>0)), array(-1, '"a"') |
||
| 249 | * @expect array('((is_array($in) && 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') |
||
| 250 | * @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') |
||
| 251 | * @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') |
||
| 252 | * @expect array('((is_array($in) && 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') |
||
| 253 | * @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') |
||
| 254 | */ |
||
| 255 | 590 | protected static function getVariableName(&$context, $var, $lookup = null, $args = null) { |
|
| 322 | |||
| 323 | /** |
||
| 324 | * Return compiled PHP code for a handlebars token |
||
| 325 | * |
||
| 326 | * @param array<string,array|string|integer> $context current compile context |
||
| 327 | * @param array<string,array|boolean> $info parsed information |
||
| 328 | * |
||
| 329 | * @return string Return compiled code segment for the token |
||
| 330 | */ |
||
| 331 | 619 | protected static function compileToken(&$context, $info) { |
|
| 358 | |||
| 359 | /** |
||
| 360 | * handle partial |
||
| 361 | * |
||
| 362 | * @param array<string,array|string|integer> $context current compile context |
||
| 363 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 364 | * |
||
| 365 | * @return string Return compiled code segment for the partial |
||
| 366 | */ |
||
| 367 | 88 | public static function partial(&$context, $vars) { |
|
| 387 | |||
| 388 | /** |
||
| 389 | * handle inline partial |
||
| 390 | * |
||
| 391 | * @param array<string,array|string|integer> $context current compile context |
||
| 392 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 393 | * |
||
| 394 | * @return string Return compiled code segment for the partial |
||
| 395 | */ |
||
| 396 | 10 | public static function inline(&$context, $vars) { |
|
| 407 | |||
| 408 | /** |
||
| 409 | * Return compiled PHP code for a handlebars inverted section begin token |
||
| 410 | * |
||
| 411 | * @param array<string,array|string|integer> $context current compile context |
||
| 412 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 413 | * |
||
| 414 | * @return string Return compiled code segment for the token |
||
| 415 | */ |
||
| 416 | 38 | protected static function invertedSection(&$context, $vars) { |
|
| 420 | |||
| 421 | /** |
||
| 422 | * Return compiled PHP code for a handlebars block custom helper begin token |
||
| 423 | * |
||
| 424 | * @param array<string,array|string|integer> $context current compile context |
||
| 425 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 426 | * @param boolean $inverted the logic will be inverted |
||
| 427 | * |
||
| 428 | * @return string Return compiled code segment for the token |
||
| 429 | */ |
||
| 430 | 60 | protected static function blockCustomHelper(&$context, $vars, $inverted = false) { |
|
| 439 | |||
| 440 | /** |
||
| 441 | * Return compiled PHP code for a handlebars block end token |
||
| 442 | * |
||
| 443 | * @param array<string,array|string|integer> $context current compile context |
||
| 444 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 445 | * @param string|null $matchop should also match to this operator |
||
| 446 | * |
||
| 447 | * @return string Return compiled code segment for the token |
||
| 448 | */ |
||
| 449 | 321 | protected static function blockEnd(&$context, &$vars, $matchop = NULL) { |
|
| 485 | |||
| 486 | /** |
||
| 487 | * Return compiled PHP code for a handlebars block begin token |
||
| 488 | * |
||
| 489 | * @param array<string,array|string|integer> $context current compile context |
||
| 490 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 491 | * |
||
| 492 | * @return string Return compiled code segment for the token |
||
| 493 | */ |
||
| 494 | 239 | protected static function blockBegin(&$context, $vars) { |
|
| 514 | |||
| 515 | /** |
||
| 516 | * compile {{#foo}} token |
||
| 517 | * |
||
| 518 | * @param array<string,array|string|integer> $context current compile context |
||
| 519 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 520 | * @param boolean $isEach the section is #each |
||
| 521 | * |
||
| 522 | * @return string|null Return compiled code segment for the token |
||
| 523 | */ |
||
| 524 | 163 | protected static function section(&$context, $vars, $isEach = false) { |
|
| 542 | |||
| 543 | /** |
||
| 544 | * compile {{with}} token |
||
| 545 | * |
||
| 546 | * @param array<string,array|string|integer> $context current compile context |
||
| 547 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 548 | * |
||
| 549 | * @return string|null Return compiled code segment for the token |
||
| 550 | */ |
||
| 551 | 28 | protected static function with(&$context, $vars) { |
|
| 558 | |||
| 559 | /** |
||
| 560 | * Return compiled PHP code for a handlebars custom helper token |
||
| 561 | * |
||
| 562 | * @param array<string,array|string|integer> $context current compile context |
||
| 563 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 564 | * @param boolean $raw is this {{{ token or not |
||
| 565 | * @param boolean $nosep true to compile without seperator |
||
| 566 | * |
||
| 567 | * @return string|null Return compiled code segment for the token when the token is custom helper |
||
| 568 | */ |
||
| 569 | 456 | protected static function customHelper(&$context, $vars, $raw, $nosep) { |
|
| 582 | |||
| 583 | /** |
||
| 584 | * Return compiled PHP code for a handlebars else token |
||
| 585 | * |
||
| 586 | * @param array<string,array|string|integer> $context current compile context |
||
| 587 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 588 | * |
||
| 589 | * @return string Return compiled code segment for the token when the token is else |
||
| 590 | */ |
||
| 591 | 50 | protected static function doElse(&$context, $vars) { |
|
| 601 | |||
| 602 | /** |
||
| 603 | * Return compiled PHP code for a handlebars log token |
||
| 604 | * |
||
| 605 | * @param array<string,array|string|integer> $context current compile context |
||
| 606 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 607 | * @param boolean $raw is this {{{ token or not |
||
| 608 | * |
||
| 609 | * @return string Return compiled code segment for the token |
||
| 610 | */ |
||
| 611 | 2 | protected static function compileLog(&$context, &$vars, $raw) { |
|
| 616 | |||
| 617 | /** |
||
| 618 | * Return compiled PHP code for a handlebars lookup token |
||
| 619 | * |
||
| 620 | * @param array<string,array|string|integer> $context current compile context |
||
| 621 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 622 | * @param boolean $raw is this {{{ token or not |
||
| 623 | * |
||
| 624 | * @return string Return compiled code segment for the token |
||
| 625 | */ |
||
| 626 | 2 | protected static function compileLookup(&$context, &$vars, $raw) { |
|
| 635 | |||
| 636 | /** |
||
| 637 | * Return compiled PHP code for template output |
||
| 638 | * |
||
| 639 | * @param array<string,array|string|integer> $context current compile context |
||
| 640 | * @param string $variable PHP code for the variable |
||
| 641 | * @param string $expression normalized handlebars expression |
||
| 642 | * @param boolean $raw is this {{{ token or not |
||
| 643 | * @param boolean $nosep true to compile without seperator |
||
| 644 | * |
||
| 645 | * @return string Return compiled code segment for the token |
||
| 646 | */ |
||
| 647 | 462 | protected static function compileOutput(&$context, $variable, $expression, $raw, $nosep) { |
|
| 655 | |||
| 656 | /** |
||
| 657 | * Return compiled PHP code for a handlebars variable token |
||
| 658 | * |
||
| 659 | * @param array<string,array|string|integer> $context current compile context |
||
| 660 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 661 | * @param boolean $raw is this {{{ token or not |
||
| 662 | * @param boolean $nosep true to compile without seperator |
||
| 663 | * |
||
| 664 | * @return string Return compiled code segment for the token |
||
| 665 | */ |
||
| 666 | 361 | protected static function compileVariable(&$context, &$vars, $raw, $nosep) { |
|
| 675 | |||
| 676 | /** |
||
| 677 | * Add usage count to context |
||
| 678 | * |
||
| 679 | * @param array<string,array|string|integer> $context current context |
||
| 680 | * @param string $category category name, can be one of: 'var', 'helpers', 'runtime' |
||
| 681 | * @param string $name used name |
||
| 682 | * @param integer $count increment |
||
| 683 | * |
||
| 684 | * @expect 1 when input array('usedCount' => array('test' => array())), 'test', 'testname' |
||
| 685 | * @expect 3 when input array('usedCount' => array('test' => array('testname' => 2))), 'test', 'testname' |
||
| 686 | * @expect 5 when input array('usedCount' => array('test' => array('testname' => 2))), 'test', 'testname', 3 |
||
| 687 | */ |
||
| 688 | 594 | protected static function addUsageCount(&$context, $category, $name, $count = 1) { |
|
| 694 | } |
||
| 695 | |||
| 696 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.