factory() публичный статический Метод

public static factory ( EventManager $eventManager, Configuration $config ) : Analyzer
$eventManager Webiny\Component\EventManager\EventManager
$config PHPSA\Configuration
Результат PHPSA\Analyzer
Пример #1
0
 /**
  * @param string $analyzerName
  * @return EventManager
  * @throws \Webiny\Component\EventManager\EventManagerException
  */
 protected function getEventManager($analyzerName)
 {
     if (!class_exists($analyzerName, true)) {
         throw new \InvalidArgumentException("Analyzer with name: {$analyzerName} doesnot exist");
     }
     /** @var \PHPSA\Analyzer\Pass\Metadata $metaData */
     $metaData = $analyzerName::getMetadata();
     if (!$metaData->allowsPhpVersion(PHP_VERSION)) {
         parent::markTestSkipped(sprintf('We cannot tests %s with %s because PHP required version is %s', $analyzerName, PHP_VERSION, $metaData->getRequiredPhpVersion()));
     }
     $analyzerConfiguration = $metaData->getConfiguration();
     $analyzerConfiguration->attribute('enabled', true);
     $config = [$analyzerName::getMetadata()->getConfiguration()];
     $em = EventManager::getInstance();
     $configuration = new Configuration([], $config);
     \PHPSA\Analyzer\Factory::factory($em, $configuration);
     return $em;
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('');
     if (extension_loaded('xdebug')) {
         /**
          * This will disable only showing stack traces on error conditions.
          */
         if (function_exists('xdebug_disable')) {
             xdebug_disable();
         }
         $output->writeln('<error>It is highly recommended to disable the XDebug extension before invoking this command.</error>');
     }
     $parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7, new \PhpParser\Lexer\Emulative(['usedAttributes' => ['comments', 'startLine', 'endLine', 'startTokenPos', 'endTokenPos']]));
     /** @var Application $application */
     $application = $this->getApplication();
     $application->compiler = new Compiler();
     $configFile = $input->getOption('config-file') ?: '.phpsa.yml';
     $configDir = realpath($input->getArgument('path'));
     $application->configuration = $this->loadConfiguration($configFile, $configDir);
     $em = EventManager::getInstance();
     Analyzer\Factory::factory($em, $application->configuration);
     $context = new Context($output, $application, $em);
     /**
      * Store option's in application's configuration
      */
     if ($input->getOption('blame')) {
         $application->configuration->setValue('blame', true);
     }
     $fileParser = new FileParser($parser, $this->getCompiler());
     $path = $input->getArgument('path');
     if (is_dir($path)) {
         $directoryIterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS));
         $output->writeln('Scanning directory <info>' . $path . '</info>');
         $count = 0;
         /** @var SplFileInfo $file */
         foreach ($directoryIterator as $file) {
             if ($file->getExtension() !== 'php') {
                 continue;
             }
             $context->debug($file->getPathname());
             $count++;
         }
         $output->writeln("Found <info>{$count} files</info>");
         if ($count > 100) {
             $output->writeln('<comment>Caution: You are trying to scan a lot of files; this might be slow. For bigger libraries, consider setting up a dedicated platform or using ci.lowl.io.</comment>');
         }
         $output->writeln('');
         /** @var SplFileInfo $file */
         foreach ($directoryIterator as $file) {
             if ($file->getExtension() !== 'php') {
                 continue;
             }
             $fileParser->parserFile($file->getPathname(), $context);
         }
     } elseif (is_file($path)) {
         $fileParser->parserFile($path, $context);
     }
     /**
      * Step 2 Recursive check ...
      */
     $application->compiler->compile($context);
     $jsonReport = $input->getOption('report-json');
     if ($jsonReport) {
         file_put_contents($jsonReport, json_encode($this->getApplication()->getIssuesCollector()->getIssues()));
     }
     $output->writeln('');
     $output->writeln('Memory usage: ' . $this->getMemoryUsage(false) . ' (peak: ' . $this->getMemoryUsage(true) . ') MB');
 }