* @copyright Since 2007 PrestaShop SA and Contributors * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) */ namespace PrestaShop\PrestaShop\Core\Domain\Product\ValueObject; use PrestaShop\PrestaShop\Core\Domain\Product\Exception\ProductConstraintException; /** * Product identity. */ class ProductId { /** * @var int */ private $productId; /** * @param int $productId * * @throws ProductConstraintException */ public function __construct($productId) { $this->assertIntegerIsGreaterThanZero($productId); $this->productId = $productId; } /** * @return int */ public function getValue() { return $this->productId; } /** * @param int $productId */ private function assertIntegerIsGreaterThanZero($productId) { if (!is_int($productId) || 0 > $productId) { throw new ProductConstraintException( sprintf('Product id %s is invalid. Product id must be number that is greater than zero.', var_export($productId, true)), ProductConstraintException::INVALID_ID ); } } }