示例#1
0
 /**
  * testCalculatesExpectedNumberOfFunctionsInProject
  *
  * @return void
  * @covers PHP_Depend_Metrics_NodeCount_Analyzer
  * @group pdepend
  * @group pdepend::metrics
  * @group pdepend::metrics::nodecount
  * @group unittest
  */
 public function testCalculatesExpectedNumberOfFunctionsInProject()
 {
     $packages = self::parseTestCaseSource(__METHOD__);
     $analyzer = new PHP_Depend_Metrics_NodeCount_Analyzer();
     $analyzer->analyze($packages);
     $metrics = $analyzer->getProjectMetrics();
     $this->assertEquals(6, $metrics['nof']);
 }
示例#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']);
 }
示例#3
0
 /**
  * Tests that the analyzer calculates the correct number of functions values.
  *
  * @return void
  */
 public function testAnalyzerCalculatesCorrectNumberOfFunctions()
 {
     $packageA = new PHP_Depend_Code_Package('A');
     $packageA->addFunction(new PHP_Depend_Code_Function('a1'));
     $packageA->addFunction(new PHP_Depend_Code_Function('a2'));
     $packageA->addFunction(new PHP_Depend_Code_Function('a3'));
     $packageB = new PHP_Depend_Code_Package('B');
     $packageB->addFunction(new PHP_Depend_Code_Function('b1'));
     $packageB->addFunction(new PHP_Depend_Code_Function('b2'));
     $packageC = new PHP_Depend_Code_Package('C');
     $packageC->addFunction(new PHP_Depend_Code_Function('c1'));
     $packages = array($packageA, $packageB, $packageC);
     $analyzer = new PHP_Depend_Metrics_NodeCount_Analyzer();
     $analyzer->analyze(new PHP_Depend_Code_NodeIterator($packages));
     $project = $analyzer->getProjectMetrics();
     $this->assertArrayHasKey('nof', $project);
     $this->assertEquals(6, $project['nof']);
     $metrics = $analyzer->getNodeMetrics($packageA);
     $this->assertArrayHasKey('nof', $metrics);
     $this->assertEquals(3, $metrics['nof']);
     $metrics = $analyzer->getNodeMetrics($packageB);
     $this->assertArrayHasKey('nof', $metrics);
     $this->assertEquals(2, $metrics['nof']);
     $metrics = $analyzer->getNodeMetrics($packageC);
     $this->assertArrayHasKey('nof', $metrics);
     $this->assertEquals(1, $metrics['nof']);
 }