/** * @param SKU $SKU * * @return Product * * @throws ProductNotFound - when product with given SKU were not found */ public function getBySku(SKU $SKU) : Product { if (isset($this->products[(string) $SKU])) { return $this->products[(string) $SKU]; } throw ProductNotFound::bySku($SKU); }
/** * @param SKU $SKU * @return Product */ public function getBySku(SKU $SKU) : Product { $product = $this->entityManager->getRepository(Product::class)->findOneBy(['sku.code' => $SKU]); if ($product === null) { ProductNotFound::bySku($SKU); } return $product; }