/**
  * Log warning while progress helper is running.
  *
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @param \Symfony\Component\Console\Helper\ProgressHelper $progress
  * @param $message
  */
 private function logWarning(OutputInterface $output, ProgressHelper $progress, $message)
 {
     $progress->clear();
     // get rid of padding (side effect of displaying progress bar)
     $output->write("\r");
     $this->logger->warning($message);
     $progress->display();
 }
 public function testClear()
 {
     $progress = new ProgressHelper();
     $progress->start($output = $this->getOutputStream(), 50);
     $progress->setCurrent(25);
     $progress->clear();
     rewind($output->getStream());
     $this->assertEquals($this->generateOutput(' 25/50 [==============>-------------]  50%') . $this->generateOutput(''), stream_get_contents($output->getStream()));
 }
Пример #3
0
 /**
  * @inheritdoc
  */
 public function execute(ResultCollection $collection, ResultCollection $aggregatedResults)
 {
     $files = $this->finder->find($this->path);
     if (0 == sizeof($files, COUNT_NORMAL)) {
         throw new \LogicException('No file found');
     }
     $progress = new ProgressHelper();
     $progress->start($this->output, sizeof($files, COUNT_NORMAL));
     // tools
     $classMap = new ClassMap();
     $tokenizer = new Tokenizer();
     $syntaxChecker = new SyntaxChecker();
     $fileAnalyzer = new FileAnalyzer($this->output, $this->withOOP, new Extractor($tokenizer), new \Hal\Metrics\Complexity\Text\Halstead\Halstead($tokenizer, new \Hal\Component\Token\TokenType()), new \Hal\Metrics\Complexity\Text\Length\Loc($tokenizer), new \Hal\Metrics\Design\Component\MaintenabilityIndex\MaintenabilityIndex($tokenizer), new \Hal\Metrics\Complexity\Component\McCabe\McCabe($tokenizer), new \Hal\Metrics\Complexity\Component\Myer\Myer($tokenizer), $classMap);
     foreach ($files as $k => $filename) {
         $progress->advance();
         // Integrity
         if (!$syntaxChecker->isCorrect($filename)) {
             $this->output->writeln(sprintf('<error>file %s is not valid and has been skipped</error>', $filename));
             unset($files[$k]);
             continue;
         }
         // Analyze
         $resultSet = $fileAnalyzer->execute($filename);
         $collection->push($resultSet);
     }
     $progress->clear();
     $progress->finish();
     if ($this->withOOP) {
         // COUPLING (should be done after parsing files)
         $this->output->write(str_pad("\rAnalyzing coupling. This will take few minutes...", 80, " "));
         $couplingAnalyzer = new CouplingAnalyzer($classMap, $collection);
         $couplingAnalyzer->execute($files);
         // LCOM (should be done after parsing files)
         $this->output->write(str_pad("\rLack of cohesion of method (lcom). This will take few minutes...", 80, " "));
         $lcomAnalyzer = new LcomAnalyzer($classMap, $collection);
         $lcomAnalyzer->execute($files);
         // Card and Agresti (should be done after parsing files)
         $this->output->write(str_pad("\rAnalyzing System complexity. This will take few minutes...", 80, " "));
         $lcomAnalyzer = new CardAndAgrestiAnalyzer($classMap, $collection);
         $lcomAnalyzer->execute($files);
     }
 }