예제 #1
0
파일: Analyzer.php 프로젝트: kingsj/core
 /**
  * Calculates the crap index for the given callable.
  *
  * @param PHP_Depend_Code_AbstractCallable $callable The context callable.
  *
  * @return float
  */
 private function _calculateCrapIndex(PHP_Depend_Code_AbstractCallable $callable)
 {
     $report = $this->_createOrReturnCoverageReport();
     $complexity = $this->_ccnAnalyzer->getCCN2($callable);
     $coverage = $report->getCoverage($callable);
     if ($coverage == 0) {
         return pow($complexity, 2) + $complexity;
     } else {
         if ($coverage > 99.5) {
             return $complexity;
         }
     }
     return pow($complexity, 2) * pow(1 - $coverage / 100, 3) + $complexity;
 }
예제 #2
0
파일: Analyzer.php 프로젝트: kingsj/core
 /**
  * Calculates the Weight Method Per Class metric, this method only counts
  * protected and public methods of parent classes.
  *
  * @param PHP_Depend_Code_Class $class The context class instance.
  *
  * @return integer
  */
 private function _calculateWMCi(PHP_Depend_Code_Class $class)
 {
     // List of methods, this method only counts not overwritten methods.
     $ccn = array();
     // First collect all methods of the context class
     foreach ($class->getMethods() as $m) {
         $ccn[$m->getName()] = $this->_cyclomaticAnalyzer->getCCN2($m);
     }
     // Get parent class and collect all non private methods.
     $parent = $class->getParentClass();
     while ($parent !== null) {
         // Count all methods
         foreach ($parent->getMethods() as $m) {
             if (!$m->isPrivate() && !isset($methods[$m->getName()])) {
                 $ccn[$m->getName()] = $this->_cyclomaticAnalyzer->getCCN2($m);
             }
         }
         // Fetch parent class
         $parent = $parent->getParentClass();
     }
     return array_sum($ccn);
 }
예제 #3
0
 /**
  * testCalculateExpectedCCN2ForDoWhileStatement
  *
  * @return void
  * @covers PHP_Depend_Metrics_CyclomaticComplexity_Analyzer
  * @group pdepend
  * @group pdepend::metrics
  * @group pdepend::metrics::cyclomaticcomplexity
  * @group unittest
  */
 public function testCalculateExpectedCCN2ForDoWhileStatement()
 {
     $packages = self::parseTestCaseSource(__METHOD__);
     $function = $packages->current()->getFunctions()->current();
     $analyzer = new PHP_Depend_Metrics_CyclomaticComplexity_Analyzer();
     $analyzer->analyze($packages);
     $this->assertEquals(3, $analyzer->getCCN2($function));
 }
예제 #4
0
파일: Analyzer.php 프로젝트: rouffj/pdepend
 /**
  * Calculates the Weight Method Per Class metric.
  *
  * @param PHP_Depend_Code_AbstractType $type The context type instance.
  *
  * @return integer[]
  * @since 1.0.6
  */
 private function _calculateWMCi(PHP_Depend_Code_AbstractType $type)
 {
     $ccn = array();
     foreach ($type->getMethods() as $method) {
         $ccn[$method->getName()] = $this->_cyclomaticAnalyzer->getCCN2($method);
     }
     return $ccn;
 }