function AbstractPatternSniff::createTokenPattern
Creates a token pattern.
Parameters
string $str The tokens string that the pattern should match.:
Return value
array The pattern step.
See also
createSkipPattern()
parse()
1 call to AbstractPatternSniff::createTokenPattern()
- AbstractPatternSniff::parse in vendor/
squizlabs/ php_codesniffer/ src/ Sniffs/ AbstractPatternSniff.php - Parses a pattern string into an array of pattern steps.
File
-
vendor/
squizlabs/ php_codesniffer/ src/ Sniffs/ AbstractPatternSniff.php, line 917
Class
Namespace
PHP_CodeSniffer\SniffsCode
private function createTokenPattern($str) {
// Don't add a space after the closing php tag as it will add a new
// whitespace token.
$tokenizer = new PHP('<?php ' . $str . '?>', null);
// Remove the <?php tag from the front and the end php tag from the back.
$tokens = $tokenizer->getTokens();
$tokens = array_slice($tokens, 1, count($tokens) - 2);
$patterns = [];
foreach ($tokens as $patternInfo) {
$patterns[] = [
'type' => 'token',
'token' => $patternInfo['code'],
'value' => $patternInfo['content'],
];
}
return $patterns;
}