Exemplo n.º 1
0
 /**
  * Evaluate rule
  *
  * @param string $rule
  * @throws \LogicException
  * @return Evaluation
  */
 public function evaluate($rule)
 {
     $result = new Evaluation();
     if (0 == strlen($rule) || is_null($rule)) {
         return $result;
     }
     $bounds = $this->bound->calculate($this->collection);
     $ruler = new \Hoa\Ruler\Ruler();
     $context = new \Hoa\Ruler\Context();
     // general
     foreach ($bounds->asArray() as $category => $values) {
         $context[$category] = (object) $values;
     }
     // by package
     foreach ($this->aggregatedResults as $aggregate) {
         $array = $aggregate->asArray();
         $c = array();
         foreach ($array as $k => $v) {
             if (is_array($v)) {
                 $v = (object) $v;
             }
             $c[$k] = $v;
         }
         $context[$aggregate->getName()] = (object) $c;
     }
     try {
         $result->setValid(true === $ruler->assert($rule, $context));
     } catch (\Hoa\Ruler\Exception\Asserter $e) {
         throw new \LogicException(sprintf('Cannot evaluate rule : %s', $e->getMessage()));
     }
     return $result;
 }
Exemplo n.º 2
0
 /**
  * @inheritdoc
  */
 public function terminate(ResultCollection $collection, ResultCollection $groupedResults)
 {
     \Twig_Autoloader::register();
     $loader = new \Twig_Loader_Filesystem(__DIR__ . '/../../../../../templates/html');
     $twig = new \Twig_Environment($loader, array('cache' => false));
     $twig->addExtension(new FormatingExtension($this->validator));
     $bound = $this->bound->calculate($collection);
     return $twig->render('summary/report.html.twig', array('keys' => array_keys(current($collection->asArray())), 'results' => $collection->asArray(), 'groupedResults' => $groupedResults, 'root' => $groupedResults->getIterator()->current(), 'relations' => $this->prepareDataRelations($collection), 'scores' => $collection->getScore()->all(), 'ruleSet' => $this->validator->getRuleSet(), 'bounds' => $bound, 'withOOP' => null !== $bound->getSum('instability')));
 }
Exemplo n.º 3
0
 /**
  * @inheritdoc
  */
 public function calculate(ResultCollection $collection, ResultCollection $groupedResults)
 {
     $calculator = new Calculator();
     $bound = $this->bound->calculate($collection);
     // list of factors of quality
     $factors = array(new MaintainabilityFactor($calculator), new ReadabilityFactor($calculator), new ComplexityFactor($calculator), new VolumeFactor($calculator), new BugPreventingFactor($calculator));
     // score
     $result = new Result();
     foreach ($factors as $qualityFactor) {
         $score = $qualityFactor->calculate($collection, $groupedResults, $bound);
         $result->push($qualityFactor->getName(), $score);
     }
     return $result;
 }
Exemplo n.º 4
0
 /**
  * @inheritdoc
  */
 public function terminate(ResultCollection $collection, ResultCollection $groupedResults)
 {
     $output = new BufferedOutput(OutputInterface::VERBOSITY_NORMAL, true);
     //        $output->write(str_pad("\x0D", 80, "\x20"));
     //        $output->writeln('');
     // overview
     $total = $this->bound->calculate($collection);
     $output->writeln(sprintf('<info>%d</info> files have been analyzed. Read and understand these <info>%s</info> lines of code will take around <info>%s</info>.', sizeof($collection, COUNT_NORMAL), $total->getSum('loc'), $this->formatTime($total->getSum('time'))));
     $output->writeln('<info>Average for each module:</info>');
     $output->writeln('');
     $hasOOP = null !== $total->getSum('instability');
     $table = new TableHelper();
     $table->setHeaders(array_merge(array('Name', 'Complexity', 'Myer Distance', 'Maintainability', 'LLOC', 'Comment weight', 'Vocabulary', 'Volume', 'Bugs', 'Difficulty'), $hasOOP ? array('lcom', 'SysComplexity', 'Instability', 'Abstractness', 'ce', 'ca') : array()))->setLayout(TableHelper::LAYOUT_DEFAULT);
     foreach ($groupedResults as $result) {
         $table->addRow(array_merge(array(str_repeat('  ', $result->getDepth()) . $result->getName(), $this->getRow($result->getBounds(), 'cyclomaticComplexity', 'average', 0), $this->getRow($result->getBounds(), 'myerDistance', 'average', 0), $this->getRow($result->getBounds(), 'maintainabilityIndex', 'average', 0), $this->getRow($result->getBounds(), 'logicalLoc', 'sum', 0), $this->getRow($result->getBounds(), 'commentWeight', 'average', 0), $this->getRow($result->getBounds(), 'vocabulary', 'average', 0), $this->getRow($result->getBounds(), 'volume', 'average', 0), $this->getRow($result->getBounds(), 'bugs', 'sum', 2), $this->getRow($result->getBounds(), 'difficulty', 'average', 0)), $hasOOP ? array($this->getRow($result->getBounds(), 'lcom', 'average', 2), $this->getRow($result->getBounds(), 'rsysc', 'average', 2), $result->getInstability()->getInstability(), $result->getAbstractness()->getAbstractness(), $this->getRow($result->getBounds(), 'efferentCoupling', 'average', 2), $this->getRow($result->getBounds(), 'afferentCoupling', 'average', 2)) : array()));
     }
     $table->render($output);
     return $output->fetch();
 }
Exemplo n.º 5
0
 /**
  * @inheritdoc
  */
 public function terminate(ResultCollection $collection, ResultCollection $groupedResults)
 {
     $bounds = $this->bound->calculate($collection);
     // root
     $xml = new \DOMDocument("1.0", "UTF-8");
     $xml->formatOutput = true;
     $root = $xml->createElement("project");
     $this->injectsBounds($root, $bounds);
     // modules
     $modules = $xml->createElement('modules');
     foreach ($groupedResults as $result) {
         $module = $xml->createElement('module');
         $this->injectsBounds($module, $result->getBounds());
         $module->setAttribute('namespace', $result->getName());
         $modules->appendChild($module);
     }
     $xml->appendChild($root);
     $root->appendChild($modules);
     return $xml->saveXML();
 }
Exemplo n.º 6
0
 /**
  * @inheritdoc
  */
 public function terminate(ResultCollection $collection, ResultCollection $groupedResults)
 {
     $output = new BufferedOutput(OutputInterface::VERBOSITY_NORMAL, true);
     //        $output->write(str_pad("\x0D", 80, "\x20"));
     //        $output->writeln('');
     // overview
     $total = $this->bound->calculate($collection);
     $output->writeln(sprintf('<info>%d</info> files have been analyzed. Read and understand these <info>%s</info> lines of code will take around <info>%s</info>.', sizeof($collection, COUNT_NORMAL), $total->getSum('loc'), $this->formatTime($total->getSum('time'))));
     $output->writeln('<info>Average for each module:</info>');
     $output->writeln('');
     $hasOOP = null !== $total->getSum('instability');
     $output->writeln('1 - Complexity');
     $output->writeln('2 - Myer Distance: derivated from Cyclomatic complexity');
     $output->writeln('3 - Maintainability');
     $output->writeln('4 - LLOC: Number of logical lines of code');
     $output->writeln('5 - Comment weight: measure the ratio between logical code and comments');
     $output->writeln('6 - Vocabulary used in code');
     $output->writeln('7 - Volume');
     $output->writeln('8 - Bugs: Number of estimated bugs by file');
     $output->writeln('9 - Difficulty of the code');
     $output->writeln('A - LCOM: Lack of cohesion of methods measures the cohesiveness of a class');
     $output->writeln('B - System complexity');
     $output->writeln('C - Instability: Indicates the class is resilience to change');
     $output->writeln('D - Abstractness: Number of abstract classes');
     $output->writeln('E - Efferent coupling (CE): Number of classes that the class depend');
     $output->writeln('F - Afferent coupling (CA): Number of classes affected by this class');
     $output->writeln('');
     $output->writeln('More details about metrics: http://www.phpmetrics.org/documentation/index.html');
     $table = new \Symfony\Component\Console\Helper\Table($output);
     $table->setHeaders(array_merge(array('1', '2', '3', '4', '5', '6', '7', '8', '9'), $hasOOP ? array('A', 'B', 'C', 'D', 'E', 'F') : array()));
     foreach ($groupedResults as $key => $result) {
         if ($result->getDepth() > 1) {
             $table->addRow(new TableSeparator());
         }
         $table->addRow(array(new TableCell($result->getName(), array('colspan' => 15))));
         $table->addRow(new TableSeparator());
         $table->addRow(array_merge(array($this->getRow($result->getBounds(), 'cyclomaticComplexity', 'average', 0), $this->getRow($result->getBounds(), 'myerDistance', 'average', 0), $this->getRow($result->getBounds(), 'maintainabilityIndex', 'average', 0), $this->getRow($result->getBounds(), 'logicalLoc', 'sum', 0), $this->getRow($result->getBounds(), 'commentWeight', 'average', 0), $this->getRow($result->getBounds(), 'vocabulary', 'average', 0), $this->getRow($result->getBounds(), 'volume', 'average', 0), $this->getRow($result->getBounds(), 'bugs', 'sum', 2), $this->getRow($result->getBounds(), 'difficulty', 'average', 0)), $hasOOP ? array($this->getRow($result->getBounds(), 'lcom', 'average', 2), $this->getRow($result->getBounds(), 'rsysc', 'average', 2), $result->getInstability()->getInstability(), $result->getAbstractness()->getAbstractness(), $this->getRow($result->getBounds(), 'efferentCoupling', 'average', 2), $this->getRow($result->getBounds(), 'afferentCoupling', 'average', 2)) : array()));
     }
     $table->render();
     return $output->fetch();
 }
Exemplo n.º 7
0
 /**
  * @inheritdoc
  */
 public function execute(ResultCollection $collection, ResultCollection $groupedResults)
 {
     $this->bound->calculate($collection);
 }