public function matches(array $tokens, $tokenIndex)
 {
     $forwardSequence = SequenceBuilder::create()->lookingForward()->expect()->token(T_WHITESPACE, ' ')->token(T_STRING)->quantity()->any()->succeeding()->token(T_NS_SEPARATOR)->token(T_STRING)->end()->end()->token(T_SEMICOLON)->quantity()->exactly(2)->token(T_WHITESPACE, "\n")->end()->end()->build();
     $backwardSequence = SequenceBuilder::create()->lookingBackward()->expect()->quantity()->exactly(1)->token(T_WHITESPACE, "\n")->end()->end()->build();
     $oneBlankLineAfterNamespace = $forwardSequence->matches($tokens, $tokenIndex);
     $oneBlankLineBeforeNamespace = $backwardSequence->matches($tokens, $tokenIndex);
     return $oneBlankLineBeforeNamespace && $oneBlankLineAfterNamespace;
 }
 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     if (!$phpcsFile->getCondition($stackPtr, T_INTERFACE)) {
         // this function is not part of an interface
         return;
     }
     $sequence = SequenceBuilder::create()->lookingBackward()->expect()->quantity()->any()->choice()->token(T_WHITESPACE)->token(T_PUBLIC)->token(T_STATIC)->end()->end()->quantity()->atLeast(3)->token(T_DOC_COMMENT)->end()->end()->build();
     /** @var $sequence \Matthias\Codesniffer\Sequence\ForwardSequence */
     if (!$sequence->matches($tokens, $stackPtr)) {
         $phpcsFile->addError('Interface method should have a doc comment', $stackPtr);
     }
 }
 /**
  * @test
  */
 public function it_fails_when_no_expectation_have_been_defined()
 {
     $this->setExpectedException('\\LogicException');
     SequenceBuilder::create()->build();
 }
 private function isFollowedByTwoNewLines(array $tokens, $tokenIndex)
 {
     $sequence = SequenceBuilder::create()->expect()->quantity()->any()->token(T_DOC_COMMENT)->end()->quantity()->atLeast(2)->token(T_WHITESPACE, "\n")->end()->end()->build();
     return $sequence->matches($tokens, $tokenIndex);
 }