From 5c49c4921402f033717bda19032b4b9beb10cc5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bar=C3=A1=C5=A1ek?= Date: Wed, 16 Feb 2022 15:12:23 +0100 Subject: [PATCH] Endpoint: Fix PhpStan. --- src/CartEndpoint.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/CartEndpoint.php b/src/CartEndpoint.php index 6788880..6b899e4 100644 --- a/src/CartEndpoint.php +++ b/src/CartEndpoint.php @@ -64,10 +64,12 @@ public function actionDefault(): void $currency = $cart->getCurrency(); $products = []; foreach ($cart->getItems() as $cartItem) { + $product = $cartItem->getProduct(); + assert($product instanceof Product); $items[] = [ 'id' => $cartItem->getId(), 'url' => $this->linkSafe(':Front:Product:detail', [ - 'slug' => $cartItem->getProduct()->getSlug(), + 'slug' => $product->getSlug(), ]), 'mainImageUrl' => (static function (?ImageInterface $image): ?string { if ($image === null) { @@ -75,13 +77,13 @@ public function actionDefault(): void } return ImageGenerator::from($image->getRelativePath(), ['w' => 150, 'h' => 150]); - })($cartItem->getProduct()->getMainImage()), + })($product->getMainImage()), 'name' => $cartItem->getName(), 'count' => $cartItem->getCount(), 'price' => $cartItem->getBasicPrice()->render(true), 'description' => $cartItem->getDescription(), ]; - $products[] = $cartItem->getProduct(); + $products[] = $product; $price = bcadd($price, $cartItem->getPrice()->getValue()); $priceWithoutVat = bcadd($priceWithoutVat, $cartItem->getPriceWithoutVat()->getValue()); } @@ -438,7 +440,7 @@ private function getItemById(int $id): ?CartItem /** - * @return array{id: int, name: string, mainImage: string|null, price: string, url: string} + * @return array{id: int, name: string, mainImage: string|null, price: string, url: string|null} */ private function formatRelated(Product $product, CurrencyInterface $currency): array {