/** * 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); } } }
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, '}')); }
/** * @dataProvider provideEquals */ public function testEquals(Token $token, $equals, $other, $caseSensitive = true) { $this->assertSame($equals, $token->equals($other, $caseSensitive)); }