/**
  * testWmciMetricIsCalculatedForCurrentAndNotParentClass
  * 
  * @return void
  */
 public function testWmciMetricIsCalculatedForCurrentAndNotParentClass()
 {
     $namespaces = self::parseCodeResourceForTest();
     $class = $namespaces->current()->getClasses()->current();
     $ccnAnalyzer = new CyclomaticComplexityAnalyzer();
     $ccnAnalyzer->setCache(new MemoryCacheDriver());
     $analyzer = new ClassLevelAnalyzer();
     $analyzer->addAnalyzer($ccnAnalyzer);
     $analyzer->analyze($namespaces);
     $metrics = $analyzer->getNodeMetrics($class);
     $this->assertEquals(2, $metrics['wmci']);
 }
Beispiel #2
0
 /**
  * Aggregates the required metrics from the registered analyzers.
  *
  * @return array(string => mixed)
  * @throws \RuntimeException If one of the required analyzers isn't set.
  */
 private function collectMetrics()
 {
     if ($this->coupling === null) {
         throw new \RuntimeException('Missing Coupling analyzer.');
     }
     if ($this->cyclomaticComplexity === null) {
         throw new \RuntimeException('Missing Cyclomatic Complexity analyzer.');
     }
     if ($this->inheritance === null) {
         throw new \RuntimeException('Missing Inheritance analyzer.');
     }
     if ($this->nodeCount === null) {
         throw new \RuntimeException('Missing Node Count analyzer.');
     }
     if ($this->nodeLoc === null) {
         throw new \RuntimeException('Missing Node LOC analyzer.');
     }
     $coupling = $this->coupling->getProjectMetrics();
     $cyclomatic = $this->cyclomaticComplexity->getProjectMetrics();
     $inheritance = $this->inheritance->getProjectMetrics();
     $nodeCount = $this->nodeCount->getProjectMetrics();
     $nodeLoc = $this->nodeLoc->getProjectMetrics();
     return array('cyclo' => $cyclomatic['ccn2'], 'loc' => $nodeLoc['eloc'], 'nom' => $nodeCount['nom'] + $nodeCount['nof'], 'noc' => $nodeCount['noc'], 'nop' => $nodeCount['nop'], 'ahh' => round($inheritance['ahh'], 3), 'andc' => round($inheritance['andc'], 3), 'fanout' => $coupling['fanout'], 'calls' => $coupling['calls']);
 }
Beispiel #3
0
 /**
  * Calculates the crap index for the given callable.
  *
  * @param  \PDepend\Source\AST\AbstractASTCallable $callable
  * @return float
  */
 private function calculateCrapIndex(AbstractASTCallable $callable)
 {
     $report = $this->createOrReturnCoverageReport();
     $complexity = $this->ccnAnalyzer->getCcn2($callable);
     $coverage = $report->getCoverage($callable);
     if ($coverage == 0) {
         return pow($complexity, 2) + $complexity;
     } elseif ($coverage > 99.5) {
         return $complexity;
     }
     return pow($complexity, 2) * pow(1 - $coverage / 100, 3) + $complexity;
 }
 /**
  * testAnalyzerCountsNumberOfMethodsForClassSize
  *
  * @return void
  */
 public function testAnalyzerCountsNumberOfMethodsForClassSize()
 {
     $namespaces = self::parseCodeResourceForTest();
     $class = $namespaces->current()->getClasses()->current();
     $ccnAnalyzer = new CyclomaticComplexityAnalyzer();
     $ccnAnalyzer->setCache(new MemoryCacheDriver());
     $analyzer = new ClassLevelAnalyzer();
     $analyzer->addAnalyzer($ccnAnalyzer);
     $analyzer->analyze($namespaces);
     $metrics = $analyzer->getNodeMetrics($class);
     $this->assertEquals(6, $metrics['csz']);
 }
 /**
  * testClassLevelAnalyzerNotRunsEndlessForDeepInterfaceHierarchy
  * 
  * @return void
  */
 public function testClassLevelAnalyzerNotRunsEndlessForDeepInterfaceHierarchy()
 {
     set_time_limit(5);
     $ccnAnalyzer = new CyclomaticComplexityAnalyzer();
     $ccnAnalyzer->setCache(new MemoryCacheDriver());
     $analyzer = new ClassLevelAnalyzer();
     $analyzer->addAnalyzer($ccnAnalyzer);
     $analyzer->analyze($this->parseCodeResourceForTest());
 }
 /**
  * Analyzes the source code associated with the calling test method and
  * returns all measured metrics.
  *
  * @return mixed
  * @since 1.0.6
  */
 private function _calculateTraitMetrics()
 {
     $namespaces = $this->parseCodeResourceForTest();
     $ccnAnalyzer = new CyclomaticComplexityAnalyzer();
     $ccnAnalyzer->setCache(new MemoryCacheDriver());
     $analyzer = new ClassLevelAnalyzer();
     $analyzer->addAnalyzer($ccnAnalyzer);
     $analyzer->analyze($namespaces);
     return $analyzer->getNodeMetrics($namespaces[0]->getTraits()->current());
 }
 /**
  * Calculates the Weight Method Per Class metric.
  *
  * @param  \PDepend\Source\AST\AbstractASTType $type
  * @return integer[]
  * @since  1.0.6
  */
 private function calculateWmci(AbstractASTType $type)
 {
     $ccn = array();
     foreach ($type->getMethods() as $method) {
         $ccn[$method->getName()] = $this->cyclomaticAnalyzer->getCcn2($method);
     }
     return $ccn;
 }
 /**
  * Returns a pre configured ccn analyzer.
  *
  * @return \PDepend\Metrics\Analyzer\CyclomaticComplexityAnalyzer
  * @since 1.0.0
  */
 private function _createAnalyzer()
 {
     $analyzer = new CyclomaticComplexityAnalyzer();
     $analyzer->setCache($this->cache);
     return $analyzer;
 }