Skip to content

Commit

Permalink
[CLEANUP] Extract method Color::shouldRenderAsHex
Browse files Browse the repository at this point in the history
Resolves #852.
  • Loading branch information
JakeQZ committed Jan 30, 2025
1 parent c8a7b5f commit 7dc3be2
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/Value/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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},
Expand Down

0 comments on commit 7dc3be2

Please sign in to comment.