/**
  * Will iterate tokens looking for comments and if found will determine the regex
  * to test the comment against.
  *
  * @param  Testable $testable The testable object
  * @return void
  */
 public function apply($testable, array $config = array())
 {
     $tokens = $testable->tokens();
     $lines = $testable->lines();
     $lineCache = $testable->lineCache();
     $inspectable = array(T_CLASS, T_VARIABLE, T_FUNCTION, T_CONST, T_DOUBLE_COLON);
     foreach ($testable->findAll(array(T_DOC_COMMENT)) as $tokenId) {
         $token = $tokens[$tokenId];
         $nextLine = $token['line'] + count(preg_split('/\\r\\n|\\r|\\n/', $token['content']));
         $parentId = false;
         if (isset($lineCache[$nextLine])) {
             $parentId = $testable->findNext($inspectable, $lineCache[$nextLine]);
         }
         if ($parentId === false && $token['line'] !== 2) {
             $this->addViolation(array('message' => 'Docblocks should only be at the beginning of the page or ' . 'before a class/function or static call.', 'line' => $token['line']));
             continue;
         }
         $parent = $tokens[$parentId];
         $content = null;
         if ($token['line'] === 2) {
             $match = 'PAGE';
         } else {
             switch ($parent['id']) {
                 case T_CLASS:
                     $match = 'CLASS';
                     break;
                 case T_DOUBLE_COLON:
                 case T_FUNCTION:
                     $match = 'METHOD';
                     break;
                 case T_VARIABLE:
                 case T_CONST:
                     $match = 'VARIABLE';
                     break;
             }
         }
         if (in_array($parent['id'], array(T_FUNCTION, T_VARIABLE), true)) {
             $content .= $tokens[$tokenId - 1]['content'];
         }
         $content .= $token['content'];
         $pattern = $this->compilePattern($match);
         $correctFormat = preg_match($this->compilePattern($match), $content) === 1;
         $hasTags = preg_match($this->compilePattern('HAS_TAGS'), $content) === 1;
         $correctTagFormat = preg_match($this->compilePattern('TAG_FORMAT'), $content) === 1;
         if (!$correctFormat) {
             $this->addViolation(array('message' => 'Docblocks are in the incorrect format.', 'line' => $token['line']));
         } elseif ($hasTags && !$correctTagFormat) {
             $this->addViolation(array('hasTags' => (int) $hasTags, 'correctTagFormat' => (int) $correctTagFormat, 'tagFormat' => $this->compilePattern('TAG_FORMAT'), 'message' => 'Tags should be last and have a blank docblock line.', 'line' => $token['line']));
         }
     }
 }
 /**
  * Will iterate the lines until it finds one with $requiredTokens
  * Once found it will find all short tags using $findPattern and
  * match against them using $matchedPattern
  *
  * @param  Testable $testable The testable object
  * @return void
  */
 public function apply($testable, array $config = array())
 {
     $message = 'Inline HTML should be in the following format: "<?=$var; ?>"';
     $lines = $testable->lines();
     $tokens = $testable->tokens();
     $lineCache = $testable->lineCache();
     $matches = array();
     foreach ($lines as $lineNumber => $line) {
         $lineTokens = isset($lineCache[$lineNumber]) ? $lineCache[$lineNumber] : array();
         if ($this->hasRequiredTokens($tokens, $lineTokens)) {
             preg_match_all($this->findPattern, $line, $matches);
             foreach ($matches as $match) {
                 if (isset($match[0]) && preg_match($this->matchPattern, $match[0]) === 0) {
                     $this->addViolation(array('message' => $message, 'line' => $lineNumber));
                 }
             }
         }
     }
 }