Flitch\File\File::seekTokenType PHP Method

seekTokenType() public method

Returns true on success and false if the token can not be found. Seeking starts from current element. If the current token matches the given type, the position is not changed. In case a stopper is supplied, the seeking will stop at the given token.
public seekTokenType ( mixed $type, boolean $backwards = false, mixed $stopper = null ) : boolean
$type mixed
$backwards boolean
$stopper mixed
return boolean
    public function seekTokenType($type, $backwards = false, $stopper = null)
    {
        $currentPosition = $this->key();
        while ($this->valid()) {
            $current = $this->current()->getType();
            if ($stopper !== null && (is_array($stopper) && in_array($current, $stopper)) || $current === $stopper) {
                break;
            }
            if (is_array($type) && in_array($current, $type) || $current === $type) {
                return true;
            }
            if ($backwards) {
                $this->prev();
            } else {
                $this->next();
            }
        }
        $this->seek($currentPosition);
        return false;
    }

Usage Example

Example #1
0
 /**
  * visitToken(): defined by TokenRuleInterface.
  *
  * @see    TokenRuleInterface::visitToken()
  * @param  File $file
  * @return void
  */
 public function visitToken(File $file)
 {
     if (!$file->seekTokenType(T_STRING, false, ';')) {
         return;
     }
     $token = $file->current();
     if (!preg_match('(^' . $this->format . '$)', $token->getLexeme())) {
         $this->addViolation($file, $token->getLine(), $token->getColumn(), sprintf('Constant name does not match format "%s"', $this->format));
     }
 }
All Usage Examples Of Flitch\File\File::seekTokenType