function PHP::findCloser
Finds a "closer" token (closing parenthesis or square bracket for example) Handle parenthesis balancing while searching for closing token
Parameters
array $tokens The list of tokens to iterate searching the closing token (as returned by token_get_all).:
int $start The starting position.:
string|string[] $openerTokens The opening character.:
string $closerChar The closing character.:
Return value
int|null The position of the closing token, if found. NULL otherwise.
2 calls to PHP::findCloser()
- PHP::parsePhpAttribute in vendor/
squizlabs/ php_codesniffer/ src/ Tokenizers/ PHP.php - PHP 8 attributes parser for PHP < 8 Handles single-line and multiline attributes.
- PHP::tokenize in vendor/
squizlabs/ php_codesniffer/ src/ Tokenizers/ PHP.php - Creates an array of tokens when given some PHP code.
File
-
vendor/
squizlabs/ php_codesniffer/ src/ Tokenizers/ PHP.php, line 3876
Class
Namespace
PHP_CodeSniffer\TokenizersCode
private function findCloser(array &$tokens, $start, $openerTokens, $closerChar) {
$numTokens = count($tokens);
$stack = [
0,
];
$closer = null;
$openerTokens = (array) $openerTokens;
for ($x = $start; $x < $numTokens; $x++) {
if (in_array($tokens[$x], $openerTokens, true) === true || is_array($tokens[$x]) === true && in_array($tokens[$x][1], $openerTokens, true) === true) {
$stack[] = $x;
}
else {
if ($tokens[$x] === $closerChar) {
array_pop($stack);
if (empty($stack) === true) {
$closer = $x;
break;
}
}
}
}
return $closer;
}