From 7dc3be2a7b7b72b0fe36e56414b64af696e8c9bd Mon Sep 17 00:00:00 2001 From: Jake Hotson Date: Thu, 30 Jan 2025 20:31:13 +0000 Subject: [PATCH] [CLEANUP] Extract method `Color::shouldRenderAsHex` Resolves #852. --- src/Value/Color.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Value/Color.php b/src/Value/Color.php index af6efa95..b657d66d 100644 --- a/src/Value/Color.php +++ b/src/Value/Color.php @@ -224,12 +224,7 @@ public function __toString(): string public function render(OutputFormat $outputFormat): string { - // Shorthand RGB color values - if ( - $outputFormat->getRGBHashNotation() - && $this->getRealName() === 'rgb' - && $this->allComponentsAreNumbers() - ) { + if ($this->shouldRenderAsHex($outputFormat)) { return $this->renderAsHex(); } @@ -240,6 +235,14 @@ public function render(OutputFormat $outputFormat): string return parent::render($outputFormat); } + private function shouldRenderAsHex(OutputFormat $outputFormat): bool + { + return + $outputFormat->getRGBHashNotation() + && $this->getRealName() === 'rgb' + && $this->allComponentsAreNumbers(); + } + /** * The function name is a concatenation of the array keys of the components, which is passed to the constructor. * However, this can be changed by calling {@see CSSFunction::setName},