本文整理汇总了PHP中PhpCsFixer\Tokenizer\Token::equals方法的典型用法代码示例。如果您正苦于以下问题:PHP Token::equals方法的具体用法?PHP Token::equals怎么用?PHP Token::equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhpCsFixer\Tokenizer\Token
的用法示例。
在下文中一共展示了Token::equals方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
/**
* {@inheritdoc}
*/
public function process(Tokens $tokens, Token $token, $index)
{
if (!$token->equals('?')) {
return;
}
$prevIndex = $tokens->getPrevMeaningfulToken($index);
$prevToken = $tokens[$prevIndex];
if ($prevToken->equalsAny(array('(', ',', array(CT::T_TYPE_COLON)))) {
$token->override(array(CT::T_NULLABLE_TYPE, '?'));
}
}
示例2: process
/**
* {@inheritdoc}
*/
public function process(Tokens $tokens, Token $token, $index)
{
if (!$token->equals('|')) {
return;
}
$prevIndex = $tokens->getPrevMeaningfulToken($index);
$prevToken = $tokens[$prevIndex];
if (!$prevToken->isGivenKind(T_STRING)) {
return;
}
$prevIndex = $tokens->getPrevMeaningfulToken($prevIndex);
$prevToken = $tokens[$prevIndex];
if (!$prevToken->equalsAny(array('(', array(CT::T_TYPE_ALTERNATION)))) {
return;
}
$token->override(array(CT::T_TYPE_ALTERNATION, '|'));
}
示例3: process
/**
* {@inheritdoc}
*/
public function process(Tokens $tokens, Token $token, $index)
{
if (!$token->equals(':')) {
return;
}
$endIndex = $tokens->getPrevMeaningfulToken($index);
if (!$tokens[$endIndex]->equals(')')) {
return;
}
$startIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $endIndex, false);
$prevIndex = $tokens->getPrevMeaningfulToken($startIndex);
$prevToken = $tokens[$prevIndex];
// if this could be a function name we need to take one more step
if ($prevToken->isGivenKind(T_STRING)) {
$prevIndex = $tokens->getPrevMeaningfulToken($prevIndex);
$prevToken = $tokens[$prevIndex];
}
if ($prevToken->isGivenKind(array(T_FUNCTION, CT::T_RETURN_REF, CT::T_USE_LAMBDA))) {
$token->override(array(CT::T_TYPE_COLON, ':'));
}
}
示例4: fixByToken
private function fixByToken(Token $token, $index)
{
foreach ($this->tokenKindCallbackMap as $kind => $callback) {
if (!$token->isGivenKind($kind)) {
continue;
}
$this->{$callback}($index);
return;
}
foreach ($this->tokenEqualsMap as $equals => $callback) {
if (!$token->equals($equals)) {
continue;
}
$this->{$callback}($index);
}
}
示例5: transformIntoDynamicVarBraces
private function transformIntoDynamicVarBraces(Tokens $tokens, Token $token, $index)
{
if (!$token->equals('$')) {
return;
}
$openIndex = $tokens->getNextMeaningfulToken($index);
if (null === $openIndex) {
return;
}
$openToken = $tokens[$openIndex];
if (!$openToken->equals('{')) {
return;
}
$closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $openIndex);
$closeToken = $tokens[$closeIndex];
$openToken->override(array(CT_DYNAMIC_VAR_BRACE_OPEN, '{'));
$closeToken->override(array(CT_DYNAMIC_VAR_BRACE_CLOSE, '}'));
}
示例6: transformIntoGroupUseBraces
private function transformIntoGroupUseBraces(Tokens $tokens, Token $token, $index)
{
if (!$token->equals('{')) {
return;
}
$prevIndex = $tokens->getPrevMeaningfulToken($index);
if (!$tokens[$prevIndex]->isGivenKind(T_NS_SEPARATOR)) {
return;
}
$closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index);
$closeToken = $tokens[$closeIndex];
$token->override(array(CT::T_GROUP_IMPORT_BRACE_OPEN, '{'));
$closeToken->override(array(CT::T_GROUP_IMPORT_BRACE_CLOSE, '}'));
}
示例7: detectBlockType
/**
* Detect type of block.
*
* @param Token $token token
*
* @return null|array array with 'type' and 'isStart' keys or null if not found
*/
public static function detectBlockType(Token $token)
{
foreach (self::getBlockEdgeDefinitions() as $type => $definition) {
if ($token->equals($definition['start'])) {
return array('type' => $type, 'isStart' => true);
}
if ($token->equals($definition['end'])) {
return array('type' => $type, 'isStart' => false);
}
}
}
示例8: testEquals
/**
* @dataProvider provideEquals
*/
public function testEquals(Token $token, $equals, $other, $caseSensitive = true)
{
$this->assertSame($equals, $token->equals($other, $caseSensitive));
}
示例9: transformIntoCurlyIndexBraces
private function transformIntoCurlyIndexBraces(Tokens $tokens, Token $token, $index)
{
if (!$token->equals('{')) {
return;
}
$prevIndex = $tokens->getPrevMeaningfulToken($index);
if (!$tokens[$prevIndex]->equalsAny(array(array(T_STRING), array(T_VARIABLE), array(CT_ARRAY_INDEX_CURLY_BRACE_CLOSE), array(CT_ARRAY_SQUARE_BRACE_CLOSE), ']', ')'))) {
return;
}
if ($tokens[$prevIndex]->isGivenKind(T_STRING) && !$tokens[$tokens->getPrevMeaningfulToken($prevIndex)]->isGivenKind(T_OBJECT_OPERATOR)) {
return;
}
if ($tokens[$prevIndex]->equals(')') && !$tokens[$tokens->getPrevMeaningfulToken($tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $prevIndex, false))]->isGivenKind(T_ARRAY)) {
return;
}
$closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index);
$closeToken = $tokens[$closeIndex];
$token->override(array(CT_ARRAY_INDEX_CURLY_BRACE_OPEN, '{'));
$closeToken->override(array(CT_ARRAY_INDEX_CURLY_BRACE_CLOSE, '}'));
}
示例10: process
/**
* {@inheritdoc}
*/
public function process(Tokens $tokens, Token $token, $index)
{
if ($token->equals('&') && $tokens[$tokens->getPrevMeaningfulToken($index)]->isGivenKind(T_FUNCTION)) {
$token->override(array(CT_RETURN_REF, '&'));
}
}