0xFFFFFF) { throw new InvalidArgumentException("int color value is invalid, must be positive and lower than 0xFFFFFF"); } $this->hex = $value; } /** * @return string */ public function getValue(): string { return $this->hex; } public static function from(string $value): Color { $color = self::tryFrom($value); if ($color == null) { var_dump($value); throw new InvalidArgumentException("The string is not an hexadecimal code"); } return $color; } public static function tryFrom(string $value): ?Color { if (!preg_match('/#(?:[0-9a-fA-F]{6})/', $value)) { return null; } return new Color($value); } }