我一直在試圖找到一種更好的寫作方式:重構條件陳述
這樣的工作,但必須有一個更清潔的方式嗎?
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;
}
對不起 - 我可以問你爲什麼傳遞快遞? –