I'm writing a functional that calls two nullable boolean APIs. If either API returns true, my function should return true. If both return false, my function should return false. Otherwise, my function should return null. In other words:
true, true -> true
true, false -> true
true, null -> true
false, false -> false
false, null -> null
null, null -> null
Is there a simple/elegant way to write this? Obviously an if-else chain like this would work, but I think it's fairly messy, especially since you have to account for that null is a falsy value.
if ($cond1 || $cond2) {
return true;
} else ($cond1 === false && $cond2 === false) {
return false;
} else {
return null;
}