public function setColor($color) { if (preg_match('/^#[a-f0-9]{6}$/i', $color)) { $this->color = $color; return $this; } throw new \InvalidArgumentException("{$color} is not a valid hex color."); }