コード例 #1
0
ファイル: HelperTest.php プロジェクト: bwoebi/recki-ct
 /**
  * @covers ::getInboundNodes
  */
 public function testGetInboundNodesWithInbound()
 {
     $in = $this->getValues(Helper::getInboundNodes($this->v[4], $this->graph));
     $this->assertEquals(2, count($in));
     $this->assertSame($this->v[2], $in[0]);
     $this->assertSame($this->v[3], $in[1]);
 }
コード例 #2
0
ファイル: PhiResolver.php プロジェクト: bwoebi/recki-ct
 public function checkForCircularReference(array $phiNodes, GraphState $state)
 {
     $graph = new DirectedAdjacencyList();
     foreach ($phiNodes as $phi) {
         $result = $phi->getResult();
         foreach ($phi->getValues() as $value) {
             $graph->ensureArc($value, $result);
         }
     }
     $cycles = $graph->getCycles();
     foreach ($cycles as $cycle) {
         if ($this->areAllUnknown($cycle)) {
             // All are unknown, process!
             $types = array();
             foreach ($cycle as $component) {
                 foreach (Helper::getInboundNodes($component, $graph) as $node) {
                     if (in_array($node, $cycle, true)) {
                         continue;
                     }
                     $types[] = $node->getType()->getType();
                 }
             }
             $types = array_unique($types);
             $newType = 0;
             switch (count($types)) {
                 case 1:
                     if ($types[0] != Type::TYPE_UNKNOWN) {
                         $newType = $types[0];
                     }
                     break;
                 case 2:
                     if (in_array(Type::TYPE_NUMERIC, $types) && in_array(Type::TYPE_LONG, $types)) {
                         $newType = Type::TYPE_NUMERIC;
                     } elseif (in_array(Type::TYPE_NUMERIC, $types) && in_array(Type::TYPE_DOUBLE, $types)) {
                         $newType = Type::TYPE_DOUBLE;
                     }
                     break;
             }
             if ($newType) {
                 foreach ($cycle as $component) {
                     $component->setType(new Type($newType));
                 }
                 return true;
             }
         }
     }
     return false;
 }