Code-TidyAll
view release on metacpan or search on metacpan
php/PHP_CodeSniffer/src/Tokenizers/CSS.php view on Meta::CPAN
'type' => 'T_OPEN_TAG',
'content' => '',
];
$newStackPtr = 1;
$numTokens = count($tokens);
$multiLineComment = false;
for ($stackPtr = 1; $stackPtr < $numTokens; $stackPtr++) {
$token = $tokens[$stackPtr];
// CSS files don't have lists, breaks etc, so convert these to
// standard strings early so they can be converted into T_STYLE
// tokens and joined with other strings if needed.
if ($token['code'] === T_BREAK
|| $token['code'] === T_LIST
|| $token['code'] === T_DEFAULT
|| $token['code'] === T_SWITCH
|| $token['code'] === T_FOR
|| $token['code'] === T_FOREACH
|| $token['code'] === T_WHILE
|| $token['code'] === T_DEC
|| $token['code'] === T_NEW
) {
$token['type'] = 'T_STRING';
$token['code'] = T_STRING;
}
$token['content'] = str_replace('^PHPCS_CSS_T_OPEN_TAG^', '<?php', $token['content']);
$token['content'] = str_replace('^PHPCS_CSS_T_CLOSE_TAG^', '?>', $token['content']);
if (PHP_CODESNIFFER_VERBOSITY > 1) {
$type = $token['type'];
$content = Util\Common::prepareForOutput($token['content']);
echo "\tProcess token $stackPtr: $type => $content".PHP_EOL;
}
if ($token['code'] === T_BITWISE_XOR
&& $tokens[($stackPtr + 1)]['content'] === 'PHPCS_CSS_T_OPEN_TAG'
) {
$content = '<?php';
for ($stackPtr += 3; $stackPtr < $numTokens; $stackPtr++) {
if ($tokens[$stackPtr]['code'] === T_BITWISE_XOR
&& $tokens[($stackPtr + 1)]['content'] === 'PHPCS_CSS_T_CLOSE_TAG'
) {
// Add the end tag and ignore the * we put at the end.
$content .= '?>';
$stackPtr += 2;
break;
} else {
$content .= $tokens[$stackPtr]['content'];
}
}
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo "\t\t=> Found embedded PHP code: ";
$cleanContent = Util\Common::prepareForOutput($content);
echo $cleanContent.PHP_EOL;
}
$finalTokens[$newStackPtr] = [
'type' => 'T_EMBEDDED_PHP',
'code' => T_EMBEDDED_PHP,
'content' => $content,
];
$newStackPtr++;
continue;
}//end if
if ($token['code'] === T_GOTO_LABEL) {
// Convert these back to T_STRING followed by T_COLON so we can
// more easily process style definitions.
$finalTokens[$newStackPtr] = [
'type' => 'T_STRING',
'code' => T_STRING,
'content' => substr($token['content'], 0, -1),
];
$newStackPtr++;
$finalTokens[$newStackPtr] = [
'type' => 'T_COLON',
'code' => T_COLON,
'content' => ':',
];
$newStackPtr++;
continue;
}
if ($token['code'] === T_FUNCTION) {
// There are no functions in CSS, so convert this to a string.
$finalTokens[$newStackPtr] = [
'type' => 'T_STRING',
'code' => T_STRING,
'content' => $token['content'],
];
$newStackPtr++;
continue;
}
if ($token['code'] === T_COMMENT
&& substr($token['content'], 0, 2) === '/*'
) {
// Multi-line comment. Record it so we can ignore other
// comment tags until we get out of this one.
$multiLineComment = true;
}
if ($token['code'] === T_COMMENT
&& $multiLineComment === false
&& (substr($token['content'], 0, 2) === '//'
|| $token['content'][0] === '#')
) {
$content = ltrim($token['content'], '#/');
// Guard against PHP7+ syntax errors by stripping
// leading zeros so the content doesn't look like an invalid int.
$leadingZero = false;
if ($content[0] === '0') {
$content = '1'.$content;
$leadingZero = true;
}
( run in 1.794 second using v1.01-cache-2.11-cpan-71847e10f99 )