/** * @inheritdoc */ protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln('PHPMetrics by Jean-François Lépine <https://twitter.com/Halleck45>'); $output->writeln(''); // config $configFactory = new ConfigFactory(); $config = $configFactory->factory($input); // files if (null === $config->getPath()->getBasePath()) { throw new \LogicException('Please provide a path to analyze'); } // files to analyze $finder = new Finder($config->getPath()->getExtensions(), $config->getPath()->getExcludedDirs(), $config->getPath()->isFollowSymlinks() ? Finder::FOLLOW_SYMLINKS : null); // prepare structures $bounds = new Bounds(); $collection = new \Hal\Component\Result\ResultCollection(); $aggregatedResults = new \Hal\Component\Result\ResultCollection(); // execute analyze $queueFactory = new QueueFactory($input, $output, $config); $queue = $queueFactory->factory($finder, $bounds); gc_disable(); $queue->execute($collection, $aggregatedResults); gc_enable(); $output->writeln('<info>done</info>'); // evaluation of success $evaluator = new Evaluator($collection, $aggregatedResults, $bounds); $result = $evaluator->evaluate($config->getFailureCondition()); // fail if failure-condition is realized return $result->isValid() ? 1 : 0; }
/** * @inheritdoc */ protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln('PHPMetrics by Jean-François Lépine <https://twitter.com/Halleck45>'); $output->writeln(''); $level = $input->getOption('level'); // config $configFactory = new ConfigFactory(); $config = $configFactory->factory($input); // files if (null === $config->getPath()->getBasePath()) { throw new \LogicException('Please provide a path to analyze'); } $finder = new Finder($config->getPath()->getExtensions(), $config->getPath()->getExcludedDirs()); // rules $rules = $config->getRuleSet(); $validator = new \Hal\Application\Rule\Validator($rules); // bounds $bounds = new Bounds(); // jobs queue planning $queue = new Queue(); $queue->push(new DoAnalyze($output, $finder, $config->getPath()->getBasePath(), !$input->getOption('without-oop')))->push(new SearchBounds($output, $bounds))->push(new DoAggregatedAnalyze($output, new DirectoryAggregatorFlat($level)))->push(new ReportRenderer($output, new Summary\Cli($validator, $bounds)))->push(new ReportWriter($config->getLogging()->getReport('html'), $output, new Summary\Html($validator, $bounds)))->push(new ReportWriter($config->getLogging()->getReport('json'), $output, new Details\Json($validator, $bounds)))->push(new ReportWriter($config->getLogging()->getReport('xml'), $output, new Summary\Xml($validator, $bounds)))->push(new ReportWriter($config->getLogging()->getReport('csv'), $output, new Details\Csv($validator, $bounds)))->push(new ReportWriter($config->getLogging()->getViolation('xml'), $output, new Xml($validator, $bounds)))->push(new ReportWriter($config->getLogging()->getChart('bubbles'), $output, new Bubbles($validator, $bounds))); // execute $collection = new \Hal\Component\Result\ResultCollection(); $aggregatedResults = new \Hal\Component\Result\ResultCollection(); $queue->execute($collection, $aggregatedResults); $output->writeln('<info>done</info>'); // evaluation of success $evaluator = new Evaluator($collection, $aggregatedResults, $bounds); $result = $evaluator->evaluate($config->getFailureCondition()); return $result->getCode(); }
/** * @inheritdoc */ protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln('PHPMetrics by Jean-François Lépine <https://twitter.com/Halleck45>'); $output->writeln(''); // config $configFactory = new ConfigFactory(); $config = $configFactory->factory($input); // files if (null === $config->getPath()->getBasePath()) { throw new \LogicException('Please provide a path to analyze'); } // files to analyze $finder = new Finder($config->getPath()->getExtensions(), $config->getPath()->getExcludedDirs(), $config->getPath()->isFollowSymlinks() ? Finder::FOLLOW_SYMLINKS : null); // prepare plugins $repository = new Repository(); foreach ($config->getExtensions()->getExtensions() as $filename) { if (!file_exists($filename) || !is_readable($filename)) { $output->writeln(sprintf('<error>Plugin %s skipped: not found</error>', $filename)); continue; } $plugin = (require_once $filename); $repository->attach($plugin); } $extensionService = new ExtensionService($repository); // prepare structures $bounds = new Bounds(); $collection = new ResultCollection(); $aggregatedResults = new ResultCollection(); // execute analyze $queueFactory = new QueueAnalyzeFactory($input, $output, $config, $extensionService); $queue = $queueFactory->factory($finder, $bounds); gc_disable(); $queue->execute($collection, $aggregatedResults); gc_enable(); $output->writeln(''); // provide data to extensions if (($n = sizeof($repository->all())) > 0) { $output->writeln(sprintf('%d %s. Executing analyzis', $n, $n > 1 ? 'plugins are enabled' : 'plugin is enabled')); $extensionService->receive($config, $collection, $aggregatedResults, $bounds); } // generating reports $output->writeln("Generating reports..."); $queueFactory = new QueueReportFactory($input, $output, $config, $extensionService); $queue = $queueFactory->factory($finder, $bounds); $queue->execute($collection, $aggregatedResults); $output->writeln('<info>Done</info>'); // evaluation of success $rule = $config->getFailureCondition(); if (null !== $rule) { $evaluator = new Evaluator($collection, $aggregatedResults, $bounds); $result = $evaluator->evaluate($rule); // fail if failure-condition is realized return $result->isValid() ? 1 : 0; } return 0; }