/** * @param int $token * @param string $value * * @return bool if true is returned, lexer will end its loop * @throws LexerException */ protected function token($token, $value) { switch ($token) { case T_FUNCTION: $this->source = new \stdClass(); $this->source->name = null; /** if name remains null, function is lambda */ $this->source->parameterList = []; break; case T_STRING: $this->source->name = $value; break; case '(': if ($this->use) { break; } $this->reflectionTokenizer->next(); $this->source->parameterList = array_merge($this->source->parameterList, ParameterLexer::build($this->reflectionTokenizer->setContinue())); break; case T_USE: $this->use = true; break; case ')': $this->use = false; break; case '{': /** * skip whole method body */ $curly = 0; foreach ($this->reflectionTokenizer->setContinue() as $innerToken => $innerValue) { switch ($innerToken) { case T_CURLY_OPEN: case '{': $curly++; break; case '}': if (--$curly <= 0) { return true; } break; } } break; } return false; }
/** * @param int $token * @param string $value * * @return bool if true is returned, lexer will end its loop * @throws LexerException */ protected function token($token, $value) { switch ($token) { case T_FUNCTION: $this->source = new \stdClass(); $this->source->annotation = null; $this->source->static = false; $this->source->abstract = false; $this->source->final = false; $this->source->visibility = 'public'; $this->source->parameterList = []; $this->reflectionTokenizer->getNext(T_STRING); $this->source->name = $this->reflectionTokenizer->current(); foreach ($this->reflectionTokenizer->getTokenStack() as $stackToken) { list($innerToken, $innerValue) = $stackToken; switch ($innerToken) { case T_DOC_COMMENT: $this->source->annotation = $innerValue; break; case T_ABSTRACT: $this->source->abstract = true; break; case T_STATIC: $this->source->static = true; break; case T_FINAL: $this->source->final = true; break; case T_PUBLIC: $this->source->visibility = 'public'; break; case T_PROTECTED: $this->source->visibility = 'protected'; break; case T_PRIVATE: $this->source->visibility = 'private'; break; } } break; case '(': /** * move to parameter list, if any */ $this->reflectionTokenizer->next(); $this->source->parameterList = array_merge($this->source->parameterList, ParameterLexer::build($this->reflectionTokenizer->setContinue())); break; case '{': /** * skip whole method body */ $curly = 0; foreach ($this->reflectionTokenizer->setContinue() as $innerToken => $innerValue) { switch ($innerToken) { case T_CURLY_OPEN: case '{': $curly++; break; case '}': if (--$curly <= 0) { return true; } break; } } break; case ';': return true; } return false; }