コード例 #1
0
 public function testResultAggregateCanBeExportedToArray()
 {
     $abstractness = $this->getMock('\\Hal\\Metrics\\Mood\\Abstractness\\Result');
     $abstractness->expects($this->once())->method('asArray')->will($this->returnValue(array('abstractness' => 1)));
     $instability = $this->getMock('\\Hal\\Metrics\\Mood\\Instability\\Result');
     $instability->expects($this->once())->method('asArray')->will($this->returnValue(array('instability' => 0.3)));
     $resultAggregate = new ResultAggregate('my');
     $resultAggregate->setAbstractness($abstractness)->setInstability($instability);
     $expected = array('name' => 'my', 'abstractness' => 1, 'instability' => 0.3, 'childs' => array(), 'depth' => 1);
     $this->assertEquals($expected, $resultAggregate->asArray());
 }
コード例 #2
0
 /**
  * @inheritdoc
  */
 public function execute(ResultCollection $collection, ResultCollection $aggregatedResults)
 {
     $this->output->write(str_pad("\rGrouping results by package/directory. This will take few minutes...", 80, " "));
     // Aggregates results
     $groupedResults = $this->aggregator->aggregates($collection);
     // metrics tools
     $abstractness = new Abstractness();
     $bounds = new Bounds();
     $instability = new Instability();
     foreach ($groupedResults as $namespace => $results) {
         // we filter aggregates to conserve only direct results
         $childs = new ResultCollection();
         foreach ($results as $r) {
             if ($namespace === dirname($r->getName())) {
                 $childs->push($r);
             }
         }
         $resultAggregate = new ResultAggregate($namespace);
         $resultAggregate->setAbstractness($abstractness->calculate($results))->setInstability($instability->calculate($results))->setBounds($bounds->calculate($results))->setChilds($childs);
         $aggregatedResults->push($resultAggregate);
     }
 }