/** * {@inheritDoc} * * @throws Exception * @throws UnexpectedTokenException If the token is not expected. */ public function current() { $token = parent::current(); $offset = $this->key(); $before = isset($this[$offset - 1]) ? $this[$offset - 1] : null; // is it an unused token? if (false === self::$sequences[$token[0]]) { throw UnexpectedTokenException::create('Token #%d (%d) is not used by this library.', $offset, $token[0]); // not in the list of expected tokens? } elseif (empty($before) && DocLexer::T_AT !== $token[0] || $before && !isset(self::$sequences[$token[0]][$before[0]])) { throw UnexpectedTokenException::create('Token #%d (%d) is not expected here.', $offset, $token[0]); // before token has another before requirement? } elseif (isset(self::$sequences[$token[0]][$before[0]]) && true !== self::$sequences[$token[0]][$before[0]]) { $ancestor = isset($this[$offset - 2]) ? $this[$offset - 2] : null; if (!$ancestor || $ancestor[0] !== self::$sequences[$token[0]][$before[0]]) { throw UnexpectedTokenException::create('Token #%d (%d) is not expected here.', $offset, $token[0]); } } return $token; }
/** * @dataProvider getTokenWithValue */ public function testGetTokenMissingValue($token) { $tokens = new Tokens(array(array($token))); $this->setExpectedException('Herrera\\Annotations\\Exception\\InvalidTokenException', "Token #0 ({$token}) is missing its value."); $tokens->current(0); }