Complex classes like Validator 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 Validator, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 31 | class Validator { |
||
| 32 | /** |
||
| 33 | * Verify template |
||
| 34 | * |
||
| 35 | * @param array<string,array|string|integer> $context Current context |
||
| 36 | * @param string $template handlebars template |
||
| 37 | */ |
||
| 38 | 720 | public static function verify(&$context, $template) { |
|
| 39 | 720 | $template = SafeString::stripExtendedComments($template); |
|
| 40 | 720 | $context['level'] = 0; |
|
| 41 | 720 | Parser::setDelimiter($context); |
|
| 42 | |||
| 43 | 720 | while (preg_match($context['tokens']['search'], $template, $matches)) { |
|
| 44 | // Skip a token when it is slash escaped |
||
| 45 | 709 | if ($context['flags']['slash'] && ($matches[Token::POS_LSPACE] === '') && preg_match('/^(.*?)(\\\\+)$/s', $matches[Token::POS_LOTHER], $escmatch)) { |
|
| 46 | 4 | if (strlen($escmatch[2]) % 4) { |
|
| 47 | 2 | static::pushToken($context, substr($matches[Token::POS_LOTHER], 0, -2) . $context['tokens']['startchar']); |
|
| 48 | 2 | $matches[Token::POS_BEGINTAG] = substr($matches[Token::POS_BEGINTAG], 1); |
|
| 49 | 2 | $template = implode('', array_slice($matches, Token::POS_BEGINTAG)); |
|
| 50 | 2 | continue; |
|
| 51 | } else { |
||
| 52 | 2 | $matches[Token::POS_LOTHER] = $escmatch[1] . str_repeat('\\', strlen($escmatch[2]) / 2); |
|
| 53 | } |
||
| 54 | } |
||
| 55 | 707 | $context['tokens']['count']++; |
|
| 56 | 707 | $V = static::token($matches, $context); |
|
| 57 | 707 | static::pushLeft($context); |
|
| 58 | 707 | if ($V) { |
|
| 59 | 668 | if (is_array($V)) { |
|
| 60 | 661 | array_push($V, $matches, $context['tokens']['partialind']); |
|
| 61 | } |
||
| 62 | 668 | static::pushToken($context, $V); |
|
| 63 | } |
||
| 64 | 707 | $template = "{$matches[Token::POS_RSPACE]}{$matches[Token::POS_ROTHER]}"; |
|
| 65 | } |
||
| 66 | 720 | static::pushToken($context, $template); |
|
| 67 | |||
| 68 | 720 | if ($context['level'] > 0) { |
|
| 69 | 6 | array_pop($context['stack']); |
|
| 70 | 6 | array_pop($context['stack']); |
|
| 71 | 6 | $token = array_pop($context['stack']); |
|
| 72 | 6 | $context['error'][] = 'Unclosed token ' . ($context['rawblock'] ? "{{{{{$token}}}}}" : "{{#{$token}}}") . ' !!'; |
|
| 73 | } |
||
| 74 | 720 | } |
|
| 75 | |||
| 76 | /** |
||
| 77 | * push left string of current token and clear it |
||
| 78 | * |
||
| 79 | * @param array<string,array|string|integer> $context Current context |
||
| 80 | */ |
||
| 81 | 707 | protected static function pushLeft(&$context) { |
|
| 85 | |||
| 86 | /** |
||
| 87 | * push a token into the stack when it is not empty string |
||
| 88 | * |
||
| 89 | * @param array<string,array|string|integer> $context Current context |
||
| 90 | * @param string|array $token a parsed token or a string |
||
| 91 | */ |
||
| 92 | 720 | protected static function pushToken(&$context, $token) { |
|
| 104 | |||
| 105 | /** |
||
| 106 | * push current token into the section stack |
||
| 107 | * |
||
| 108 | * @param array<string,array|string|integer> $context Current context |
||
| 109 | * @param string $operation operation string |
||
| 110 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 111 | */ |
||
| 112 | 352 | protected static function pushStack(&$context, $operation, $vars) { |
|
| 113 | 352 | list($levels, $spvar, $var) = Expression::analyze($context, $vars[0]); |
|
| 114 | 352 | $context['stack'][] = $context['currentToken'][Token::POS_INNERTAG]; |
|
| 115 | 352 | $context['stack'][] = Expression::toString($levels, $spvar, $var); |
|
| 116 | 352 | $context['stack'][] = $operation; |
|
| 117 | 352 | $context['level']++; |
|
| 118 | 352 | } |
|
| 119 | |||
| 120 | /** |
||
| 121 | * Verify delimiters and operators |
||
| 122 | * |
||
| 123 | * @param string[] $token detected handlebars {{ }} token |
||
| 124 | * @param array<string,array|string|integer> $context current compile context |
||
| 125 | * |
||
| 126 | * @return boolean|null Return true when invalid |
||
| 127 | * |
||
| 128 | * @expect null when input array_fill(0, 11, ''), array() |
||
| 129 | * @expect null when input array(0, 0, 0, 0, 0, '{{', '#', '...', '}}'), array() |
||
| 130 | * @expect true when input array(0, 0, 0, 0, 0, '{', '#', '...', '}'), array() |
||
| 131 | */ |
||
| 132 | 708 | protected static function delimiter($token, &$context) { |
|
| 144 | |||
| 145 | /** |
||
| 146 | * Verify operators |
||
| 147 | * |
||
| 148 | * @param string $operator the operator string |
||
| 149 | * @param array<string,array|string|integer> $context current compile context |
||
| 150 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 151 | * |
||
| 152 | * @return boolean|integer|null Return true when invalid or detected |
||
|
1 ignored issue
–
show
|
|||
| 153 | * |
||
| 154 | * @expect null when input '', array(), array() |
||
| 155 | * @expect 2 when input '^', array('usedFeature' => array('isec' => 1), 'level' => 0, 'currentToken' => array(0,0,0,0,0,0,0,0), 'flags' => array('spvar' => 0)), array(array('foo')) |
||
| 156 | * @expect true when input '/', array('stack' => array('[with]', '#'), 'level' => 1, 'currentToken' => array(0,0,0,0,0,0,0,'with'), 'flags' => array('nohbh' => 0)), array(array()) |
||
| 157 | * @expect 4 when input '#', array('usedFeature' => array('sec' => 3), 'level' => 0, 'currentToken' => array(0,0,0,0,0,0,0,0), 'flags' => array('spvar' => 0), 'elseif' => false, 'elselvl' => array()), array(array('x')) |
||
| 158 | * @expect 5 when input '#', array('usedFeature' => array('if' => 4), 'level' => 0, 'currentToken' => array(0,0,0,0,0,0,0,0), 'flags' => array('spvar' => 0, 'nohbh' => 0), 'elseif' => false, 'elselvl' => array()), array(array('if')) |
||
| 159 | * @expect 6 when input '#', array('usedFeature' => array('with' => 5), 'level' => 0, 'flags' => array('nohbh' => 0, 'runpart' => 0, 'spvar' => 0), 'currentToken' => array(0,0,0,0,0,0,0,0), 'elseif' => false, 'elselvl' => array()), array(array('with')) |
||
| 160 | * @expect 7 when input '#', array('usedFeature' => array('each' => 6), 'level' => 0, 'currentToken' => array(0,0,0,0,0,0,0,0), 'flags' => array('spvar' => 0, 'nohbh' => 0), 'elseif' => false, 'elselvl' => array()), array(array('each')) |
||
| 161 | * @expect 8 when input '#', array('usedFeature' => array('unless' => 7), 'level' => 0, 'currentToken' => array(0,0,0,0,0,0,0,0), 'flags' => array('spvar' => 0, 'nohbh' => 0), 'elseif' => false, 'elselvl' => array()), array(array('unless')) |
||
| 162 | * @expect 9 when input '#', array('blockhelpers' => array('abc' => ''), 'usedFeature' => array('bhelper' => 8), 'level' => 0, 'currentToken' => array(0,0,0,0,0,0,0,0), 'flags' => array('spvar' => 0), 'elseif' => false, 'elselvl' => array()), array(array('abc')) |
||
| 163 | * @expect 11 when input '#', array('hbhelpers' => array('abc' => ''), 'usedFeature' => array('hbhelper' => 10), 'level' => 0, 'currentToken' => array(0,0,0,0,0,0,0,0), 'flags' => array('spvar' => 0), 'elseif' => false, 'elselvl' => array()), array(array('abc')) |
||
| 164 | * @expect true when input '>', array('basedir' => array('.'), 'fileext' => array('.tmpl'), 'usedFeature' => array('partial' => 7), 'level' => 0, 'flags' => array('skippartial' => 0, 'runpart' => 0, 'spvar' => 0), 'currentToken' => array(0,0,0,0,0,0,0,0), 'elseif' => false, 'elselvl' => array()), array('test') |
||
| 165 | */ |
||
| 166 | 669 | protected static function operator($operator, &$context, &$vars) { |
|
| 167 | switch ($operator) { |
||
| 168 | 669 | case '#*': |
|
| 169 | 10 | static::pushLeft($context); |
|
| 170 | 10 | $context['stack'][] = count($context['parsed'][0]); |
|
| 171 | 10 | static::pushStack($context, '#*', $vars); |
|
| 172 | 10 | array_unshift($context['inlinepartial'], ''); |
|
| 173 | 10 | return static::inline($context, $vars); |
|
| 174 | |||
| 175 | case '#>': |
||
| 176 | 13 | static::pushLeft($context); |
|
| 177 | 13 | $context['stack'][] = count($context['parsed'][0]); |
|
| 178 | 13 | static::pushStack($context, '#>', $vars); |
|
| 179 | 13 | array_unshift($context['partialblock'], ''); |
|
| 180 | 13 | return static::partial($context, $vars); |
|
| 181 | |||
| 182 | case '>': |
||
| 183 | 89 | return static::partial($context, $vars); |
|
| 184 | |||
| 185 | case '^': |
||
| 186 | 66 | if (!isset($vars[0][0])) { |
|
| 187 | 24 | if (!$context['flags']['else']) { |
|
| 188 | 1 | $context['error'][] = 'Do not support {{^}}, you should do compile with LightnCandy::FLAG_ELSE flag'; |
|
| 189 | 1 | return; |
|
| 190 | } else { |
||
| 191 | 23 | return static::doElse($context, $vars); |
|
| 192 | } |
||
| 193 | } |
||
| 194 | |||
| 195 | 42 | if (static::isBlockHelper($context, $vars)) { |
|
| 196 | 3 | static::pushStack($context, '#', $vars); |
|
| 197 | 3 | return static::blockCustomHelper($context, $vars, true); |
|
| 198 | } |
||
| 199 | |||
| 200 | 39 | static::pushStack($context, '^', $vars); |
|
| 201 | 39 | return static::invertedSection($context, $vars); |
|
| 202 | |||
| 203 | case '/': |
||
| 204 | 335 | $r = static::blockEnd($context, $vars); |
|
| 205 | 335 | array_pop($context['stack']); |
|
| 206 | 335 | array_pop($context['stack']); |
|
| 207 | 335 | array_pop($context['stack']); |
|
| 208 | 335 | return $r; |
|
| 209 | |||
| 210 | 509 | case '#': |
|
| 211 | 308 | if (static::isBlockHelper($context, $vars)) { |
|
| 212 | 59 | static::pushStack($context, '#', $vars); |
|
| 213 | 59 | return static::blockCustomHelper($context, $vars); |
|
| 214 | } |
||
| 215 | |||
| 216 | 256 | if (!$context['elseif']) { |
|
| 217 | 256 | static::pushStack($context, '#', $vars); |
|
| 218 | } |
||
| 219 | |||
| 220 | 256 | return static::blockBegin($context, $vars); |
|
| 221 | } |
||
| 222 | 509 | } |
|
| 223 | |||
| 224 | /** |
||
| 225 | * validate inline partial begin token |
||
| 226 | * |
||
| 227 | * @param array<string,array|string|integer> $context current compile context |
||
| 228 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 229 | * |
||
| 230 | * @return boolean|null Return true when inline partial ends |
||
| 231 | */ |
||
| 232 | 668 | protected static function inlinePartial(&$context, $vars) { |
|
| 258 | |||
| 259 | /** |
||
| 260 | * validate partial block token |
||
| 261 | * |
||
| 262 | * @param array<string,array|string|integer> $context current compile context |
||
| 263 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 264 | * |
||
| 265 | * @return boolean|null Return true when partial block ends |
||
| 266 | */ |
||
| 267 | 668 | protected static function partialBlock(&$context, $vars) { |
|
| 296 | |||
| 297 | /** |
||
| 298 | * handle else if |
||
| 299 | * |
||
| 300 | * @param array<string,array|string|integer> $context current compile context |
||
| 301 | */ |
||
| 302 | 75 | protected static function doElseIf(&$context) { |
|
| 309 | |||
| 310 | /** |
||
| 311 | * validate block begin token |
||
| 312 | * |
||
| 313 | * @param array<string,array|string|integer> $context current compile context |
||
| 314 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 315 | * |
||
| 316 | * @return boolean Return true always |
||
| 317 | */ |
||
| 318 | 255 | protected static function blockBegin(&$context, $vars) { |
|
| 335 | |||
| 336 | /** |
||
| 337 | * validate builtin helpers |
||
| 338 | * |
||
| 339 | * @param array<string,array|string|integer> $context current compile context |
||
| 340 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 341 | */ |
||
| 342 | 145 | protected static function builtin(&$context, $vars) { |
|
| 354 | |||
| 355 | /** |
||
| 356 | * validate section token |
||
| 357 | * |
||
| 358 | * @param array<string,array|string|integer> $context current compile context |
||
| 359 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 360 | * @param boolean $isEach the section is #each |
||
| 361 | * |
||
| 362 | * @return boolean Return true always |
||
| 363 | */ |
||
| 364 | 171 | protected static function section(&$context, $vars, $isEach = false) { |
|
| 375 | |||
| 376 | /** |
||
| 377 | * validate with token |
||
| 378 | * |
||
| 379 | * @param array<string,array|string|integer> $context current compile context |
||
| 380 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 381 | * |
||
| 382 | * @return boolean Return true always |
||
| 383 | */ |
||
| 384 | 31 | protected static function with(&$context, $vars) { |
|
| 385 | 31 | static::builtin($context, $vars); |
|
| 386 | 31 | return true; |
|
| 387 | } |
||
| 388 | |||
| 389 | /** |
||
| 390 | * validate unless token |
||
| 391 | * |
||
| 392 | * @param array<string,array|string|integer> $context current compile context |
||
| 393 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 394 | * |
||
| 395 | * @return boolean Return true always |
||
| 396 | */ |
||
| 397 | 7 | protected static function unless(&$context, $vars) { |
|
| 402 | |||
| 403 | /** |
||
| 404 | * validate if token |
||
| 405 | * |
||
| 406 | * @param array<string,array|string|integer> $context current compile context |
||
| 407 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 408 | * |
||
| 409 | * @return boolean Return true always |
||
| 410 | */ |
||
| 411 | 69 | protected static function doIf(&$context, $vars) { |
|
| 416 | |||
| 417 | /** |
||
| 418 | * validate block custom helper token |
||
| 419 | * |
||
| 420 | * @param array<string,array|string|integer> $context current compile context |
||
| 421 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 422 | * @param boolean $inverted the logic will be inverted |
||
| 423 | * |
||
| 424 | * @return integer|null Return number of used custom helpers |
||
|
1 ignored issue
–
show
|
|||
| 425 | */ |
||
| 426 | 61 | protected static function blockCustomHelper(&$context, $vars, $inverted = false) { |
|
| 427 | 61 | if (is_string($vars[0][0])) { |
|
| 428 | // detect handlebars custom helpers. |
||
| 429 | 61 | if (isset($context['hbhelpers'][$vars[0][0]])) { |
|
| 430 | 58 | return ++$context['usedFeature']['hbhelper']; |
|
| 431 | } |
||
| 432 | |||
| 433 | // detect block custom helpers. |
||
| 434 | 3 | if (isset($context['blockhelpers'][$vars[0][0]])) { |
|
| 435 | 3 | return ++$context['usedFeature']['bhelper']; |
|
| 436 | } |
||
| 437 | } |
||
| 438 | } |
||
| 439 | |||
| 440 | /** |
||
| 441 | * validate inverted section |
||
| 442 | * |
||
| 443 | * @param array<string,array|string|integer> $context current compile context |
||
| 444 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 445 | * |
||
| 446 | * @return integer Return number of inverted sections |
||
|
1 ignored issue
–
show
|
|||
| 447 | */ |
||
| 448 | 38 | protected static function invertedSection(&$context, $vars) { |
|
| 449 | 38 | return ++$context['usedFeature']['isec']; |
|
| 450 | } |
||
| 451 | |||
| 452 | /** |
||
| 453 | * Return compiled PHP code for a handlebars block end token |
||
| 454 | * |
||
| 455 | * @param array<string,array|string|integer> $context current compile context |
||
| 456 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 457 | * @param string|null $match should also match to this operator |
||
| 458 | * |
||
| 459 | * @return boolean Return true |
||
| 460 | */ |
||
| 461 | 347 | protected static function blockEnd(&$context, &$vars, $match = null) { |
|
| 462 | 347 | $context['level']--; |
|
| 463 | 347 | $c = count($context['stack']) - 2; |
|
| 464 | 347 | $pop = ($c >= 0) ? $context['stack'][$c + 1] : ''; |
|
| 465 | 347 | if (($match !== null) && ($match !== $pop)) { |
|
| 466 | 3 | return; |
|
| 467 | } |
||
| 468 | 347 | $pop2 = ($c >= 0) ? $context['stack'][$c]: ''; |
|
| 469 | 347 | switch ($context['currentToken'][Token::POS_INNERTAG]) { |
|
| 470 | 328 | case 'with': |
|
| 471 | 35 | if (!$context['flags']['nohbh']) { |
|
| 472 | 33 | if ($pop2 !== '[with]') { |
|
| 473 | 1 | $context['error'][] = 'Unexpect token: {{/with}} !'; |
|
| 474 | 1 | return; |
|
| 475 | } |
||
| 476 | } |
||
| 477 | 34 | return true; |
|
| 478 | } |
||
| 479 | |||
| 480 | switch($pop) { |
||
| 481 | 328 | case '#>': |
|
| 482 | case '#*': |
||
| 483 | case '#': |
||
| 484 | 1 | case '^': |
|
| 485 | 327 | list($levels, $spvar, $var) = Expression::analyze($context, $vars[0]); |
|
| 486 | 327 | $v = Expression::toString($levels, $spvar, $var); |
|
| 487 | 327 | if ($pop2 !== $v) { |
|
| 488 | 2 | $context['error'][] = 'Unexpect token ' . Token::toString($context['currentToken']) . " ! Previous token {{{$pop}$pop2}} is not closed"; |
|
| 489 | 2 | return; |
|
| 490 | } |
||
| 491 | 325 | if (count($context['elselvl']) > 0) { |
|
| 492 | 228 | $vars[0][-1] = $context['elselvl'][0]; |
|
| 493 | 228 | array_shift($context['elselvl']); |
|
| 494 | } |
||
| 495 | 325 | return true; |
|
| 496 | default: |
||
| 497 | 1 | $context['error'][] = 'Unexpect token: ' . Token::toString($context['currentToken']) . ' !'; |
|
| 498 | 1 | return; |
|
| 499 | } |
||
| 500 | } |
||
| 501 | |||
| 502 | /** |
||
| 503 | * handle delimiter change |
||
| 504 | * |
||
| 505 | * @param array<string,array|string|integer> $context current compile context |
||
| 506 | * |
||
| 507 | * @return boolean|null Return true when delimiter changed |
||
| 508 | */ |
||
| 509 | 697 | protected static function isDelimiter(&$context) { |
|
| 510 | 697 | if (preg_match('/^=\s*([^ ]+)\s+([^ ]+)\s*=$/', $context['currentToken'][Token::POS_INNERTAG], $matched)) { |
|
| 511 | 15 | $context['usedFeature']['delimiter']++; |
|
| 512 | 15 | Parser::setDelimiter($context, $matched[1], $matched[2]); |
|
| 513 | 15 | return true; |
|
| 514 | } |
||
| 515 | 688 | } |
|
| 516 | |||
| 517 | /** |
||
| 518 | * handle raw block |
||
| 519 | * |
||
| 520 | * @param string[] $token detected handlebars {{ }} token |
||
| 521 | * @param array<string,array|string|integer> $context current compile context |
||
| 522 | * |
||
| 523 | * @return boolean|null Return true when in rawblock mode |
||
| 524 | */ |
||
| 525 | 707 | protected static function rawblock(&$token, &$context) { |
|
| 526 | 707 | $inner = $token[Token::POS_INNERTAG]; |
|
| 527 | 707 | trim($inner); |
|
| 528 | |||
| 529 | // skip parse when inside raw block |
||
| 530 | 707 | if ($context['rawblock'] && !(($token[Token::POS_BEGINRAW] === '{{') && ($token[Token::POS_OP] === '/') && ($context['rawblock'] === $inner))) { |
|
| 531 | 4 | return true; |
|
| 532 | } |
||
| 533 | |||
| 534 | 707 | $token[Token::POS_INNERTAG] = $inner; |
|
| 535 | |||
| 536 | // Handle raw block |
||
| 537 | 707 | if ($token[Token::POS_BEGINRAW] === '{{') { |
|
| 538 | 7 | if ($token[Token::POS_ENDRAW] !== '}}') { |
|
| 539 | 1 | $context['error'][] = 'Bad token ' . Token::toString($token) . ' ! Do you mean ' . Token::toString($token, array(Token::POS_ENDRAW => '}}')) . ' ?'; |
|
| 540 | } |
||
| 541 | 7 | if ($context['rawblock']) { |
|
| 542 | 4 | Parser::setDelimiter($context); |
|
| 543 | 4 | $context['rawblock'] = false; |
|
| 544 | } else { |
||
| 545 | 7 | if ($token[Token::POS_OP]) { |
|
| 546 | 1 | $context['error'][] = "Wrong raw block begin with " . Token::toString($token) . ' ! Remove "' . $token[Token::POS_OP] . '" to fix this issue.'; |
|
| 547 | } |
||
| 548 | 7 | $context['rawblock'] = $token[Token::POS_INNERTAG]; |
|
| 549 | 7 | Parser::setDelimiter($context); |
|
| 550 | 7 | $token[Token::POS_OP] = '#'; |
|
| 551 | } |
||
| 552 | 7 | $token[Token::POS_ENDRAW] = '}}'; |
|
| 553 | } |
||
| 554 | 707 | } |
|
| 555 | |||
| 556 | /** |
||
| 557 | * handle comment |
||
| 558 | * |
||
| 559 | * @param string[] $token detected handlebars {{ }} token |
||
| 560 | * @param array<string,array|string|integer> $context current compile context |
||
| 561 | * |
||
| 562 | * @return boolean|null Return true when is comment |
||
| 563 | */ |
||
| 564 | 688 | protected static function comment(&$token, &$context) { |
|
| 570 | |||
| 571 | /** |
||
| 572 | * Collect handlebars usage information, detect template error. |
||
| 573 | * |
||
| 574 | * @param string[] $token detected handlebars {{ }} token |
||
| 575 | * @param array<string,array|string|integer> $context current compile context |
||
| 576 | */ |
||
| 577 | 707 | protected static function token(&$token, &$context) { |
|
| 578 | 707 | $context['currentToken'] = &$token; |
|
| 579 | |||
| 652 | |||
| 653 | /** |
||
| 654 | * Return 1 or larger number when else token detected |
||
| 655 | * |
||
| 656 | * @param array<string,array|string|integer> $context current compile context |
||
| 657 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 658 | * |
||
| 659 | * @return integer Return 1 or larger number when else token detected |
||
|
1 ignored issue
–
show
|
|||
| 660 | */ |
||
| 661 | 50 | protected static function doElse(&$context, $vars) { |
|
| 675 | |||
| 676 | /** |
||
| 677 | * Return true when this is {{log ...}} |
||
| 678 | * |
||
| 679 | * @param array<string,array|string|integer> $context current compile context |
||
| 680 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 681 | * |
||
| 682 | * @return boolean|null Return true when it is custom helper |
||
| 683 | */ |
||
| 684 | 348 | public static function log(&$context, $vars) { |
|
| 695 | |||
| 696 | /** |
||
| 697 | * Return true when this is {{lookup ...}} |
||
| 698 | * |
||
| 699 | * @param array<string,array|string|integer> $context current compile context |
||
| 700 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 701 | * |
||
| 702 | * @return boolean|null Return true when it is custom helper |
||
| 703 | */ |
||
| 704 | 348 | public static function lookup(&$context, $vars) { |
|
| 717 | |||
| 718 | /** |
||
| 719 | * Return true when the name is listed in helper table |
||
| 720 | * |
||
| 721 | * @param array<string,array|string|integer> $context current compile context |
||
| 722 | * @param string $name token name |
||
| 723 | * |
||
| 724 | * @return boolean Return true when it is custom helper |
||
| 725 | */ |
||
| 726 | 465 | public static function helper(&$context, $name) { |
|
| 739 | |||
| 740 | /** |
||
| 741 | * detect for block custom helper |
||
| 742 | * |
||
| 743 | * @param array<string,array|string|integer> $context current compile context |
||
| 744 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 745 | * |
||
| 746 | * @return boolean|null Return true when this token is block custom helper |
||
| 747 | */ |
||
| 748 | 339 | protected static function isBlockHelper($context, $vars) { |
|
| 759 | |||
| 760 | /** |
||
| 761 | * validate inline partial |
||
| 762 | * |
||
| 763 | * @param array<string,array|string|integer> $context current compile context |
||
| 764 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 765 | * |
||
| 766 | * @return boolean Return true always |
||
| 767 | */ |
||
| 768 | 10 | protected static function inline(&$context, $vars) { |
|
| 780 | |||
| 781 | /** |
||
| 782 | * validate partial |
||
| 783 | * |
||
| 784 | * @param array<string,array|string|integer> $context current compile context |
||
| 785 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 786 | * |
||
| 787 | * @return integer|boolean Return 1 or larger number for runtime partial, return true for other case |
||
|
1 ignored issue
–
show
|
|||
| 788 | */ |
||
| 789 | 93 | protected static function partial(&$context, $vars) { |
|
| 811 | |||
| 812 | /** |
||
| 813 | * Modify $token when spacing rules matched. |
||
| 814 | * |
||
| 815 | * @param array<string> $token detected handlebars {{ }} token |
||
| 816 | * @param array<string,array|string|integer> $context current compile context |
||
| 817 | * @param boolean $nost do not do stand alone logic |
||
| 818 | * |
||
| 819 | * @return string|null Return compiled code segment for the token |
||
| 820 | */ |
||
| 821 | 697 | protected static function spacing(&$token, &$context, $nost = false) { |
|
| 872 | } |
||
| 873 | |||
| 874 |
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.