/** * {@inheritdoc} */ public function process($context, Result $result, Collection $collection) { $this->result = $result; $this->collection = $collection; $this->docParser = new DocParser(); $this->docParser->setIgnoreNotImportedAnnotations(true); $phpdoc = $namespace = false; $tokenParser = new TokenParser($context->getFileContent()); while ($token = $tokenParser->next(false)) { if (false === is_array($token)) { continue; } switch ($token[0]) { case T_DOC_COMMENT: if ($phpdoc !== false) { $this->processDocComment($phpdoc); $phpdoc = false; } $phpdoc = $token[1]; break; case T_NAMESPACE: $namespace = $tokenParser->parseNamespace(); break; case T_USE: // add imports to doc parser to be able to use annotation without FQCN. foreach ($tokenParser->parseUseStatement() as $alias => $target) { if ($target[0] === '\\') { $target = substr($target, 1); } $imports[$alias] = $target; } $this->docParser->setImports($imports); break; case T_CLASS: $token = $tokenParser->next(false); $class = $namespace ? $namespace . '\\' . $token[1] : $token[1]; $this->dispatchEvent(Events::TOKEN_PHP_CLASS, new Context\PHP\PHPClass($class, $phpdoc), $phpdoc); break; case T_VARIABLE: $this->dispatchEvent(Events::TOKEN_PHP_VARIABLE, new Context\PHP\PHPVariable(substr($token[1], 1), isset($class) ? $class : null, $phpdoc), $phpdoc); break; case T_FUNCTION: $token = $tokenParser->next(false); if (!is_array($token)) { continue; } $this->dispatchEvent(Events::TOKEN_PHP_FUNCTION, new Context\PHP\PHPFunction($token[1], isset($class) ? $class : null, $phpdoc), $phpdoc); break; } } }