public static function standardiseToken($token)
{
if (isset($token[1]) === false) {
if (isset(self::$_resolveTokenCache[$token[0]]) === true) {
return self::$_resolveTokenCache[$token[0]];
}
} else {
$cacheKey = null;
if ($token[0] === T_STRING) {
$cacheKey = strtolower($token[1]);
} else {
if ($token[0] !== T_CURLY_OPEN) {
$cacheKey = $token[0];
}
}
if ($cacheKey !== null && isset(self::$_resolveTokenCache[$cacheKey]) === true) {
$newToken = self::$_resolveTokenCache[$cacheKey];
$newToken['content'] = $token[1];
return $newToken;
}
}
if (isset($token[1]) === false) {
return self::resolveSimpleToken($token[0]);
}
if ($token[0] === T_STRING) {
switch ($cacheKey) {
case 'false':
$newToken['type'] = 'T_FALSE';
break;
case 'true':
$newToken['type'] = 'T_TRUE';
break;
case 'null':
$newToken['type'] = 'T_NULL';
break;
case 'self':
$newToken['type'] = 'T_SELF';
break;
case 'parent':
$newToken['type'] = 'T_PARENT';
break;
default:
$newToken['type'] = 'T_STRING';
break;
}
$newToken['code'] = constant($newToken['type']);
self::$_resolveTokenCache[$cacheKey] = $newToken;
} else {
if ($token[0] === T_CURLY_OPEN) {
$newToken = array('code' => T_OPEN_CURLY_BRACKET, 'type' => 'T_OPEN_CURLY_BRACKET');
} else {
$newToken = array('code' => $token[0], 'type' => token_name($token[0]));
self::$_resolveTokenCache[$token[0]] = $newToken;
}
}
//end if
$newToken['content'] = $token[1];
return $newToken;
}
/** * Creates a token pattern. * * @param string $str The tokens string that the pattern should match. * * @return array The pattern step. * @see _createSkipPattern() * @see _parse() */ private function _createTokenPattern($str) { // Don't add a space after the closing php tag as it will add a new // whitespace token. $tokens = token_get_all('<?php ' . $str . '?>'); // Remove the <?php tag from the front and the end php tag from the back. $tokens = array_slice($tokens, 1, count($tokens) - 2); foreach ($tokens as &$token) { $token = PHP_CodeSniffer_Tokenizers_PHP::standardiseToken($token); } $patterns = array(); foreach ($tokens as $patternInfo) { $patterns[] = array('type' => 'token', 'token' => $patternInfo['code'], 'value' => $patternInfo['content']); } return $patterns; }