$this->isColorValue(), 'size' => $this->isSizeValue(), 'number' => $this->isNumberValue(), default => false }; } public function getValueAs(string $type): mixed { return match($type) { 'color' => $this->getColorValue(), 'size' => $this->getSizeValue(), 'number' => $this->getNumberValue(), default => $this->value }; } private function isColorValue(): bool { return preg_match('/^(#[0-9a-fA-F]{3,8}|rgb|hsl|oklch|color)/', $this->value) === 1; } private function isSizeValue(): bool { return preg_match('/^\d+(\.\d+)?(px|em|rem|%|vh|vw)$/', $this->value) === 1; } private function isNumberValue(): bool { return is_numeric($this->value); } private function getColorValue(): CssColor { if ($this->isColorValue()) { $format = match(true) { str_starts_with($this->value, '#') => ColorFormat::HEX, str_starts_with($this->value, 'rgb') => ColorFormat::RGB, str_starts_with($this->value, 'hsl') => ColorFormat::HSL, str_starts_with($this->value, 'oklch') => ColorFormat::OKLCH, default => ColorFormat::HEX }; return new CssColor($this->value, $format); } throw new \InvalidArgumentException('Value is not a color'); } private function getSizeValue(): string { return $this->value; } private function getNumberValue(): float { return (float) $this->value; } }