public function isPaymentTypeAvailable(PaymentType $paymentType) { switch ($paymentType->getValue()) { case PaymentType::CASH: return $this->cashPaymentAvailable; case PaymentType::BANK: return $this->bankPaymentAvailable; case PaymentType::CARD: return $this->cardPaymentAvailable; default: throw new \LogicException(); } }
public function __construct(Cart $cart, $number, PaymentType $paymentType) { if (count($cart->getItems()) === 0) { throw new InvalidEnumException('Cannot create order from empty cart.'); } if (strlen($number) !== self::NUMBER_LENGTH) { throw new EntityInvalidArgumentException(sprintf('Order number length must be exactly %d characters.', self::NUMBER_LENGTH)); } $this->number = $number; $this->paymentType = $paymentType->getValue(); $cart->setOrder($this); $this->cart = $cart; }