Пример #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     # If possible log to stderr because stdout receives the dot file
     $logger = new SymfonyConsoleOutput($output instanceof ConsoleOutput ? $output->getErrorOutput() : $output);
     $project = new Project($logger);
     if ($input->getOption('quiet')) {
         $logger->setReportingLevel(Logger::ERROR);
     } else {
         if ($input->getOption('verbose')) {
             $logger->setReportingLevel(Logger::INFO);
         }
     }
     SourceHandler::addSourcesToProject($input, $project);
     # Necessary setup to generate the objectGraph
     $project->addAnalyzer(new Parser(new \PhpParser\Parser(new Lexer())));
     $project->addAnalyzer(new NameResolver());
     $project->addAnalyzer($objectGraph = new ObjectGraph());
     $project->analyze();
     $graphviz = new GraphvizConverter();
     $graphviz->setGraph($objectGraph);
     # Console configuration
     $graphviz->setNamespaceWhitelist($input->getOption('namespaces'));
     $graphviz->setShowNamespace($input->getOption('show-namespace'));
     $graphviz->setShowOnlyConnected($input->getOption('show-only-connected'));
     $graphviz->setClusterByNamespace($input->getOption('cluster-namespaces'));
     $graphviz->setNestClusters($input->getOption('nest-clusters'));
     $output->write($graphviz->generate());
 }
Пример #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $logger = new SymfonyConsoleOutput($output);
     $project = new Project($logger);
     if ($input->getOption('quiet')) {
         $logger->setReportingLevel(Logger::ERROR);
     } else {
         if ($input->getOption('verbose')) {
             $logger->setReportingLevel(Logger::INFO);
         }
     }
     # Fall back to UTC if date.timezone is not set
     $dateTimezone = ini_get('date.timezone');
     if (empty($dateTimezone)) {
         $logger->warning('date.timezone not set, falling back to UTC');
         date_default_timezone_set('UTC');
     }
     SourceHandler::addSourcesToProject($input, $project);
     $analyzers = NULL !== $input->getOption('config') ? require $input->getOption('config') : Project::getDefaultConfig();
     # Configure listener
     $listener = NULL;
     if (NULL !== $input->getOption('report')) {
         $format = NULL === $input->getOption('format') ? 'plain' : $input->getOption('format');
         if ('plain' === $format) {
             $listener = new Plain(fopen($input->getOption('report'), 'w'));
         } else {
             if (0 === strpos($format, 'json')) {
                 $options = 0;
                 if ('json-pretty' === $format) {
                     $options = JSON_PRETTY_PRINT;
                 }
                 $json = new JsonFormatter($options);
                 $listener = new Json(fopen($input->getOption('report'), 'w'), $json);
             } else {
                 throw new \RuntimeException("Unsupported report format '{$format}'");
             }
         }
     } else {
         if (!$input->getOption('quiet')) {
             $listener = new Plain(\STDOUT);
         }
     }
     if (NULL !== $listener) {
         $project->addListener($listener);
     }
     $project->addAnalyzers($analyzers);
     $project->analyze();
     $analyzerReports = $project->getAnalyzerReports();
     if (count($analyzerReports) > 0) {
         return 1;
     } else {
         $output->writeln('Nothing found to report.');
         return 0;
     }
 }