/** * 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']); }
/** * testAnalyzerAlsoCalculatesCCNAndCCN2OfClosureInMethod * * @return void * @covers PHP_Depend_Metrics_CyclomaticComplexity_Analyzer * @group pdepend * @group pdepend::metrics * @group pdepend::metrics::cyclomaticcomplexity * @group unittest */ public function testAnalyzerAlsoCalculatesCCNAndCCN2OfClosureInMethod() { $analyzer = new PHP_Depend_Metrics_CyclomaticComplexity_Analyzer(); $analyzer->analyze(self::parseTestCaseSource(__METHOD__)); $expected = array('ccn' => 3, 'ccn2' => 3); $actual = $analyzer->getProjectMetrics(); $this->assertEquals($expected, $actual); }