paymentMethod = match ($paymentMethod){ 'credit' => new CreditCardService(), 'apple' => new ApplePayService(), 'google' => new GooglePayService(), default => throw new \InvalidArgumentException("You must pass in either credit, apple or google as the payment method.") }; } /** * pay * * @return string */ public function pay(){ return $this->paymentMethod->pay(); } }