# 08 - Podmienky musia byť napísané jednoducho
Pod podmienkami sa myslia všetky boolean expressions. Komplikované podmienky sa ťažko čítajú, ťažko chápu a sú náchylné na chyby.
Presné pravidlá
1. V jednej podmienke je zakázané miešať AND a OR operátory
Nesprávne:
if (((!is_null($deliveryType) && $deliveryType->id == DeliveryType::POST_SK_FOREIGN) || (!is_null($deliveryAddress) && !($deliveryAddress->isSlovakia() || $deliveryAddress->isCzechRepublic()))) && (!is_null($paymentType) && $paymentType->isCash())) {
// ...
}
Správne:
$isDeliveryForeign = !is_null($deliveryType)
&& $deliveryType->id == DeliveryType::POST_SK_FOREIGN;
$isAddressForeign = !is_null($deliveryAddress)
&& !$deliveryAddress->isSlovakia()
&& !$deliveryAddress->isCzechRepublic();
$isOrderForeign = $isDeliveryForeign || $isAddressForeign;
$isPaymentCash = !is_null($paymentType) && $paymentType->isCash();
if ($isOrderForeign && $isPaymentCash) {
// ...
}