/** * @param EventManager $eventManager * @param Configuration $config * @return Analyzer */ public static function factory(EventManager $eventManager, Configuration $config) { $analyzersConfig = $config->getValue('analyzers'); $filterEnabled = function ($passClass) use($config, $analyzersConfig) { /** @var AnalyzerPass\Metadata $passMetadata */ $passMetadata = $passClass::getMetadata(); if (!isset($analyzersConfig[$passMetadata->getName()])) { return false; } if (!$analyzersConfig[$passMetadata->getName()]['enabled']) { return false; } if (!$passMetadata->allowsPhpVersion($config->getValue('language_level'))) { return false; } return true; }; $instanciate = function ($passClass) use($analyzersConfig) { $passName = $passClass::getMetadata()->getName(); return new $passClass($analyzersConfig[$passName]); }; $analyzer = new Analyzer($eventManager); $analyzer->registerExpressionPasses(array_map($instanciate, array_filter(self::getExpressionPasses(), $filterEnabled))); $analyzer->registerStatementPasses(array_map($instanciate, array_filter(self::getStatementPasses(), $filterEnabled))); $analyzer->registerScalarPasses(array_map($instanciate, array_filter(self::getScalarPasses(), $filterEnabled))); $analyzer->bind(); return $analyzer; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $analyzerConfiguration = Analyzer\Factory::getPassesConfigurations(); $configuration = new Configuration([], $analyzerConfiguration); $configTree = $configuration->getConfigTreeBuilder($analyzerConfiguration)->buildTree(); $dumper = new YamlReferenceDumper(); $output->writeln($dumper->dumpNode($configTree)); }