Example #1
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']);
 }
Example #2
0
 /**
  * Tests that the analyzer aggregates the expected project values.
  *
  * @return void
  */
 public function testAnalyzerCalculatesCorrectProjectMetrics()
 {
     $source = dirname(__FILE__) . '/../../_code/comments/';
     $packages = self::parseSource($source);
     $analyzer = new PHP_Depend_Metrics_NodeLoc_Analyzer();
     $analyzer->analyze($packages);
     $actual = $analyzer->getProjectMetrics();
     $expected = array('loc' => 260, 'cloc' => 144, 'eloc' => 89, 'ncloc' => 116);
     $this->assertEquals($expected, $actual);
 }
Example #3
0
 /**
  * Creates a ready to use node loc analyzer.
  *
  * @return PHP_Depend_Metrics_NodeLoc_Analyzer
  * @since 1.0.0
  */
 private function _createAnalyzer()
 {
     $analyzer = new PHP_Depend_Metrics_NodeLoc_Analyzer();
     $analyzer->setCache($this->_cache);
     return $analyzer;
 }
Example #4
0
 /**
  * testAnalyzerIgnoresFilesWithoutFileName
  *
  * @return void
  * @covers PHP_Depend_Metrics_NodeLoc_Analyzer
  * @group pdepend
  * @group pdepend::metrics
  * @group pdepend::metrics::nodeloc
  * @group unittest
  */
 public function testAnalyzerIgnoresFilesWithoutFileName()
 {
     $file = new PHP_Depend_Code_File(null);
     $file->setUUID(42);
     $analyzer = new PHP_Depend_Metrics_NodeLoc_Analyzer();
     $analyzer->visitFile($file);
     $metrics = $analyzer->getNodeMetrics($file);
     $this->assertEquals(array(), $metrics);
 }
Example #5
0
 /**
  * testCalculatesExpectedLLocForDoWhileStatement
  *
  * @return void
  * @covers PHP_Depend_Metrics_NodeLoc_Analyzer
  * @group pdepend
  * @group pdepend::metrics
  * @group pdepend::metrics::nodeloc
  * @group unittest
  */
 public function testCalculatesExpectedLLocForDoWhileStatement()
 {
     $packages = self::parseTestCaseSource(__METHOD__);
     $function = $packages->current()->getFunctions()->current();
     $analyzer = new PHP_Depend_Metrics_NodeLoc_Analyzer();
     $analyzer->analyze($packages);
     $metrics = $analyzer->getNodeMetrics($function);
     $this->assertEquals(3, $metrics['lloc']);
 }
Example #6
0
 /**
  * Tests the result of the phpunit logger with some real analyzers.
  *
  * @return void
  * @covers PHP_Depend_Log_Phpunit_Xml
  * @group pdepend
  * @group pdepend::logs
  * @group pdepend::logs::summary
  * @group unittest
  */
 public function testPHPUnitLoggerResult()
 {
     $packages = self::parseTestCaseSource(__METHOD__);
     $logger = new PHP_Depend_Log_Phpunit_Xml();
     $logger->setLogFile($this->_tempFile);
     $logger->setCode($packages);
     $analyzer0 = new PHP_Depend_Metrics_CyclomaticComplexity_Analyzer();
     $analyzer0->analyze($packages);
     $analyzer1 = new PHP_Depend_Metrics_ClassLevel_Analyzer();
     $analyzer1->addAnalyzer($analyzer0);
     $analyzer1->analyze($packages);
     $analyzer2 = new PHP_Depend_Metrics_CodeRank_Analyzer();
     $analyzer2->analyze($packages);
     $analyzer3 = new PHP_Depend_Metrics_Coupling_Analyzer();
     $analyzer3->analyze($packages);
     $analyzer4 = new PHP_Depend_Metrics_Hierarchy_Analyzer();
     $analyzer4->analyze($packages);
     $analyzer5 = new PHP_Depend_Metrics_Inheritance_Analyzer();
     $analyzer5->analyze($packages);
     $analyzer6 = new PHP_Depend_Metrics_NodeCount_Analyzer();
     $analyzer6->analyze($packages);
     $analyzer7 = new PHP_Depend_Metrics_NodeLoc_Analyzer();
     $analyzer7->analyze($packages);
     $logger->log($analyzer0);
     $logger->log($analyzer1);
     $logger->log($analyzer2);
     $logger->log($analyzer3);
     $logger->log($analyzer4);
     $logger->log($analyzer5);
     $logger->log($analyzer6);
     $logger->log($analyzer7);
     $logger->close();
     $actual = file_get_contents($this->_tempFile);
     $expected = $this->_loadExpected('phpunit-log.xml');
     $this->assertXmlStringEqualsXmlString($expected, $actual);
 }