public isAnonymousClass ( integer $index ) : boolean | ||
$index | integer | |
Résultat | boolean |
public function isAnonymousClass($index)
{
$tokens = $this->tokens;
$token = $tokens[$index];
if (!$token->isClassy()) {
throw new \LogicException(sprintf('No classy token at given index %d.', $index));
}
if (!$token->isGivenKind(T_CLASS)) {
return false;
}
return $tokens[$tokens->getPrevMeaningfulToken($index)]->isGivenKind(T_NEW);
}
/** * @dataProvider provideIsAnonymousClassCases */ public function testIsAnonymousClass($source, array $expected) { $tokensAnalyzer = new TokensAnalyzer(Tokens::fromCode($source)); foreach ($expected as $index => $expectedValue) { $this->assertSame($expectedValue, $tokensAnalyzer->isAnonymousClass($index)); } }