getProduct(); if ($product === null) { throw new \RuntimeException('ValidationJob requires an existing ProductDTO.'); } $result->addLog(sprintf('[%s] validating product %s.', $this->getName(), $product->getName())); if (trim($product->getName()) === '') { throw new ImportException('Product name cannot be empty.'); } if ($product->getPrice() !== null && $product->getPrice()->getAmount() < 0) { throw new ImportException('Product price cannot be negative.'); } if ($product->getInventory() !== null && $product->getInventory()->getStockQuantity() < 0) { throw new ImportException('Inventory stock quantity cannot be negative.'); } if ($product->getBarcode() === null && $product->getSku() === null) { throw new ImportException('Product must contain either a barcode or SKU.'); } $result->addLog(sprintf('[%s] product %s validated successfully.', $this->getName(), $product->getId())); return $result; } }