I have a small function that delivers the value that has the highest priority, which for now is not defined anywhere, just by order as I evaluate the values:
public function obtenerValorMasImportante($datos = null) {
if ($datos->getDato1()) {
return 'dato1';
}
if ($datos->getDatoX()) {
return 'datox';
}
if ($datos->getLoQueSea()) {
return 'loquesea';
}
if ($datos->getOtraCosa()) {
return 'otracosa';
}
return false;
}
The problem is simple: the code works, but What happens if I have 100 values? I would have to write 100 if
and it's not a good idea, neither do ideas flow in this moment of the day.
I do not have much control over the $datos
object, so it is not an option to modify it or add information to it.
How could I reduce the amount of if? or failing to make the code independent of the amount of values.