public function resolve(Phi $vertex, GraphState $state) { $types = []; foreach ($vertex->getVariables() as $value) { $types[] = $value->getType()->getType(); } $types = array_unique($types); switch (count($types)) { case 1: if ($types[0] !== Type::TYPE_UNKNOWN || 0 === count($vertex->getValues())) { // resolve variables to result $this->removePhi($vertex, $state); return true; } break; case 2: if (in_array(Type::TYPE_NUMERIC, $types)) { if (in_array(Type::TYPE_LONG, $types) || in_array(Type::TYPE_DOUBLE, $types)) { $this->removePhi($vertex, $state); return true; } elseif (in_array(Type::TYPE_BOOLEAN, $types)) { $vertex->getResult()->setType(new Type(Type::TYPE_NUMERIC)); $this->removePhi($vertex, $state); return true; } } break; } return false; }
/** * @covers ::replaceVariable */ public function testReplaceVariablesNeither() { $phi = new Phi($r = new Variable()); $phi->addValue($a = new Variable()); $phi->addValue($b = new Variable()); $phi->replaceVariable(new Variable(), new Variable()); $this->assertSame([$r, $a, $b], $phi->getVariables()); }