From 16f0ca6767ed3f1cb2f07793b6f43539784006fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bar=C3=A1=C5=A1ek?= Date: Mon, 12 Sep 2022 10:56:01 +0200 Subject: [PATCH] Fix basic PhpStan errors. --- src/Api/CmsOrderEndpoint.php | 29 +++++++++++++------------- src/Api/DTO/CmsOrderFeedList.php | 4 ++-- src/Notification/OrderNotification.php | 2 +- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/Api/CmsOrderEndpoint.php b/src/Api/CmsOrderEndpoint.php index 024a259..5fb06f2 100644 --- a/src/Api/CmsOrderEndpoint.php +++ b/src/Api/CmsOrderEndpoint.php @@ -119,11 +119,9 @@ public function actionDefault( $sum = []; $return = []; foreach ($feed['orders'] as $order) { - assert($order instanceof Order); $documents = []; if (isset($feed['invoices'][$order->getId()])) { $invoice = $feed['invoices'][$order->getId()]; - assert($invoice instanceof InvoiceInterface); $documents[] = new CmsOrderFeedDocument( url: $invoice->getDownloadLink(), label: '🧾', @@ -160,18 +158,20 @@ public function actionDefault( premium: $order->getCustomer()->isPremium(), ban: $order->getCustomer()->isBan(), ), - delivery: new CmsOrderFeedDelivery( - id: $deliveryItem?->getId(), - name: $deliveryItem?->getLabel(), - price: $order->getDeliveryPrice()->render(true), - color: $deliveryItem?->getColor(), - ), - payment: new CmsOrderFeedPayment( - id: $paymentItem?->getId(), - name: $paymentItem?->getName(), - price: $order->getPaymentPrice()->render(true), - color: $paymentItem?->getColor(), - ), + delivery: $deliveryItem !== null + ? new CmsOrderFeedDelivery( + id: $deliveryItem->getId(), + name: $deliveryItem->getLabel(), + price: $order->getDeliveryPrice()->render(true), + color: $deliveryItem->getColor(), + ) : null, + payment: $paymentItem !== null + ? new CmsOrderFeedPayment( + id: $paymentItem->getId(), + name: $paymentItem->getName(), + price: $order->getPaymentPrice()->render(true), + color: $paymentItem->getColor(), + ) : null, items: (static function ($items): array { $return = []; foreach ($items as $item) { @@ -194,7 +194,6 @@ public function actionDefault( payments: (static function ($items): array { $return = []; foreach ($items as $item) { - assert($item instanceof OrderOnlinePayment); $return[] = [ 'id' => $item->getId(), ]; diff --git a/src/Api/DTO/CmsOrderFeedList.php b/src/Api/DTO/CmsOrderFeedList.php index b14a440..ce29a52 100644 --- a/src/Api/DTO/CmsOrderFeedList.php +++ b/src/Api/DTO/CmsOrderFeedList.php @@ -30,8 +30,8 @@ public function __construct( public string $updatedDate, public int $package, public CmsOrderFeedCustomer $customer, - public CmsOrderFeedDelivery $delivery, - public CmsOrderFeedPayment $payment, + public ?CmsOrderFeedDelivery $delivery, + public ?CmsOrderFeedPayment $payment, public array $items, public array $documents, public array $payments, diff --git a/src/Notification/OrderNotification.php b/src/Notification/OrderNotification.php index bdf9044..1d0e1d3 100644 --- a/src/Notification/OrderNotification.php +++ b/src/Notification/OrderNotification.php @@ -83,7 +83,7 @@ public function sendNotification( } if ($notification->getType()->value === OrderNotificationType::Email->value) { $this->sendEmail($order, $notification->getStatus(), $attachments); - } elseif ($notification->getType()->value === OrderNotificationType::Sms->value) { + } else { $this->sendSms($order, $notification->getStatus()); } }