PhpCsFixer\Tokenizer\TokensAnalyzer::isAnonymousClass PHP Method

isAnonymousClass() public method

Check if there is an anonymous class under given index.
public isAnonymousClass ( integer $index ) : boolean
$index integer
return 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);
    }

Usage Example

 /**
  * @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));
     }
 }
All Usage Examples Of PhpCsFixer\Tokenizer\TokensAnalyzer::isAnonymousClass