From 73332f95c819b3cb1b8eeb29a9f1ee94c7aaefc5 Mon Sep 17 00:00:00 2001 From: Jake Hotson Date: Mon, 27 Jan 2025 01:23:44 +0000 Subject: [PATCH] [CLEANUP] Add `Color::getRealName` method The DocBlock should explain. --- src/Value/Color.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Value/Color.php b/src/Value/Color.php index 07f11c346..ee5e7a5c0 100644 --- a/src/Value/Color.php +++ b/src/Value/Color.php @@ -227,7 +227,7 @@ public function render(OutputFormat $outputFormat): string // Shorthand RGB color values if ( $outputFormat->getRGBHashNotation() - && \implode('', \array_keys($this->aComponents)) === 'rgb' + && $this->getRealName() === 'rgb' && $this->allComponentsAreNumbers() ) { $result = \sprintf( @@ -242,6 +242,16 @@ public function render(OutputFormat $outputFormat): string return parent::render($outputFormat); } + /** + * 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}, + * so is not reliable in situations where it's necessary to determine the function name based on the components. + */ + private function getRealName(): string + { + return \implode('', \array_keys($this->aComponents)); + } + /** * Test whether all color components are absolute numbers (CSS type `number`), not percentages or anything else. * If any component is not an instance of `Size`, the method will also return `false`.