Esempio n. 1
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 ProgressBar($this->output);
     $progress->start(sizeof($files, COUNT_NORMAL));
     // tools
     $classMap = new ClassMap();
     $tokenizer = new Tokenizer(new CacheMemory());
     $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\MaintainabilityIndex\MaintainabilityIndex(), 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
         try {
             $resultSet = $fileAnalyzer->execute($filename);
         } catch (NoTokenizableException $e) {
             $this->output->writeln(sprintf("<error>file %s has been skipped: \n%s</error>", $filename, $e->getMessage()));
             unset($files[$k]);
             continue;
         } catch (\Exception $e) {
             throw new \Exception(sprintf("a '%s' exception occured analyzing file %s\nMessage: %s", get_class($e), $filename, $e->getMessage()) . sprintf("\n------------\nStack:\n%s", $e->getTraceAsString()) . sprintf("\n------------\nDo not hesitate to report a bug: https://github.com/Halleck45/PhpMetrics/issues"), 0, $e->getPrevious());
         }
         $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);
     }
 }
Esempio n. 2
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);
     }
 }