Skip to content

Commit 589c1e2

Browse files
Simplify
1 parent fe583a5 commit 589c1e2

File tree

1 file changed

+8
-20
lines changed

1 file changed

+8
-20
lines changed

src/Field/Style/BadgeStyle.php

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,13 @@ public function getStyle(): ?string
6565
return null;
6666
}
6767

68-
return self::generateStyle($this->style);
68+
69+
$style = [];
70+
foreach ($this->style as $key => $value) {
71+
$style[] = sprintf('%s:%s;', $key, $value);
72+
}
73+
74+
return implode(' ', $style);
6975
}
7076

7177
private function addClass(string $class): self
@@ -82,27 +88,9 @@ private function addStyle(string $key, string $value): self
8288
return $this;
8389
}
8490

85-
/**
86-
* @param array<string, string> $properties
87-
*/
88-
private static function generateStyle(array $properties): string
89-
{
90-
$style = [];
91-
foreach ($properties as $key => $value) {
92-
$style[] = sprintf('%s:%s;', $key, $value);
93-
}
94-
95-
return implode(' ', $style);
96-
}
97-
98-
private static function isSupportedColor(string $color): bool
99-
{
100-
return 1 === preg_match('/^#[0-9a-f]{6}$/iD', $color);
101-
}
102-
10391
private static function generateTextClassFromBackgroundColor(string $backgroundColor): string
10492
{
105-
if (!self::isSupportedColor($backgroundColor)) {
93+
if (1 !== preg_match('/^#[0-9a-f]{6}$/iD', $backgroundColor)) {
10694
throw new \InvalidArgumentException(sprintf('Only full 6-digit hexadecimal color are supported to generate the appropriate text color ("%s" given).', $backgroundColor));
10795
}
10896

0 commit comments

Comments
 (0)