Skip to content

Commit

Permalink
Endpoint: Fix PhpStan.
Browse files Browse the repository at this point in the history
  • Loading branch information
janbarasek committed Feb 16, 2022
1 parent 804f6dc commit 5c49c49
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/CartEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,26 @@ 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) {
return null;
}

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());
}
Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit 5c49c49

Please sign in to comment.