* @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\AttributeGroup\Attribute\ValueObject; use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Attribute\Exception\AttributeConstraintException; /** * Provides identification data of Attribute */ final class AttributeId { /** * @var int */ private $attributeId; /** * @param int $attributeId * * @throws AttributeConstraintException */ public function __construct($attributeId) { $this->assertIsIntegerGreaterThanZero($attributeId); $this->attributeId = $attributeId; } /** * @return int */ public function getValue() { return $this->attributeId; } /** * Validates that the value is integer and is greater than zero * * @param int $value * * @throws AttributeConstraintException */ private function assertIsIntegerGreaterThanZero($value) { if (!is_int($value) || 0 >= $value) { throw new AttributeConstraintException(sprintf('Invalid attribute id "%s".', var_export($value, true)), AttributeConstraintException::INVALID_ID); } } }