vendredi 23 juin 2017

refactoring conditional statment

I been trying to find a better way of writing:

This works but there must be a cleaner way right?

public static function checkCourierCountry($courier, $country)
{
    if (isset(self::shippingGroups()['shippingGroups']['europe']) &&
        in_array($country, self::shippingGroups()['shippingGroups']['europe'])) {
        return true;
    }
    if (isset(self::shippingGroups()['shippingGroups']['fedex']) &&
        in_array($country, self::shippingGroups()['shippingGroups']['fedex'])) {
        return true;
    }
    if (isset(self::shippingGroups()['shippingGroups']['parcelForce']) &&
        in_array($country, self::shippingGroups()['shippingGroups']['parcelForce'])) {
        return true;
    }
    return false;
}

Aucun commentaire:

Enregistrer un commentaire