Skip to content

Commit ecaccc5

Browse files
committed
Further changes suggested in review
1 parent e966c06 commit ecaccc5

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/Value/Color.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,7 @@ private function renderAsHex(): string
303303
*/
304304
private function shouldRenderInModernSyntax(): bool
305305
{
306-
static $colorFunctionsThatWithMixedValueTypesCannotBeRenderedInLegacySyntax = ['rgb', 'rgba'];
307-
$colorFunction = $this->getRealName();
308-
if (!\in_array($colorFunction, $colorFunctionsThatWithMixedValueTypesCannotBeRenderedInLegacySyntax, true)) {
306+
if (!$this->colorFunctionMayHaveMixedValueTypes($this->getRealName())) {
309307
return false;
310308
}
311309

@@ -317,7 +315,7 @@ private function shouldRenderInModernSyntax(): bool
317315
// So it is not necessary to check it. It's also always last, hence `break` rather than `continue`.
318316
break;
319317
}
320-
if (!$value instanceof Size) {
318+
if (!($value instanceof Size)) {
321319
// Unexpected, unknown, or modified via the API
322320
return false;
323321
}
@@ -336,6 +334,19 @@ private function shouldRenderInModernSyntax(): bool
336334
return $hasPercentage && $hasNumber;
337335
}
338336

337+
/**
338+
* Some color functions, such as `rgb`,
339+
* may have a mixture of `percentage`, `number`, or possibly other types in their arguments.
340+
*
341+
* Note that this excludes the alpha component, which is treated separately.
342+
*/
343+
private function colorFunctionMayHaveMixedValueTypes(string $function): bool
344+
{
345+
$functionsThatMayHaveMixedValueTypes = ['rgb', 'rgba'];
346+
347+
return \in_array($function, $functionsThatMayHaveMixedValueTypes, true);
348+
}
349+
339350
/**
340351
* @return non-empty-string
341352
*/

0 commit comments

Comments
 (0)