public function getCommonAncestorType(IType $type, IType $otherType)
{
if ($type->isEqualTo($otherType)) {
return $type;
} elseif ($type->isParentTypeOf($otherType)) {
return $type;
} elseif ($otherType->isParentTypeOf($type)) {
return $otherType;
}
$parentTypes = $this->getAncestorTypes($type);
$otherParentTypes = $this->getAncestorTypes($otherType);
/** @var $commonParentTypes IType[] */
$commonParentTypes = array_intersect_key($parentTypes, $otherParentTypes);
return $this->getCompositeType($commonParentTypes);
}