/** * @param Project $project */ public function analyze(Project $project) { $logger = $project->getLogger(); foreach ($project->getSplFileInfos() as $splFileInfo) { try { $source = file($splFileInfo->getRealPath()); $code = join('', $source); } catch (\RuntimeException $e) { $project->addReport(new StringReport($e->getMessage())); continue; } try { $logger->info('Parsing ' . $splFileInfo->getRealPath()); $tree = $this->parser->parse($code); $project->addFile(new File($splFileInfo, $source, $tree)); } catch (Error $e) { $project->getLogger()->warning('[' . $this->getName() . '] ' . 'Error while parsing ' . $splFileInfo->getRealPath() . ' : ' . $e->getMessage()); $project->addReport(new FileParserErrorReport($splFileInfo, $e)); } } }
public function enterNode(Node $node) { if ($node instanceof Namespace_ && NULL !== $node->name) { $this->currentNamespace = join('\\', $node->name->parts); } else { if ($node instanceof Use_ && $node->type === Use_::TYPE_NORMAL) { $this->currentUseStatements[] = $node; } else { if ($node instanceof PhpParserClass || $node instanceof PhpParserInterface) { /** @var ParsedObject|NULL $object */ $object = NULL; if ($node instanceof PhpParserClass) { $object = new ParsedClass($this->currentNamespace, $this->currentUseStatements, $node, $this->currentFile); } else { if ($node instanceof PhpParserInterface) { $object = new ParsedInterface($this->currentNamespace, $this->currentUseStatements, $node, $this->currentFile); } } if (NULL !== $object) { try { $this->addObject($object); } catch (ObjectAlreadyExistsException $e) { $existingObject = $this->getObjectByFqn($object->getName()); $msg = 'Multiple declarations of the same type are not supported. Symbol ' . $object->getName() . ' from ' . $this->currentFile->getSplFile()->getRealPath() . ':' . $node->getLine(); if ($existingObject instanceof ParsedObject) { $msg .= ' already found in ' . $existingObject->getFile()->getSplFile()->getRealPath() . ':' . $existingObject->getNode()->getLine() . ' ; only the first ' . 'encounter is used'; } else { if ($existingObject instanceof ReflectedObject) { $msg .= ' clashes with internal ' . strtolower($existingObject->getKind()) . ' ' . $existingObject->getName(); } else { throw new \RuntimeException('Unknown existing object ' . $existingObject->getName()); } } $this->project->getLogger()->warning($msg); } } } } } }