Further refactoring

This commit is contained in:
2023-06-27 10:03:22 +01:00
parent dbd4ccb35d
commit e97ef857ef

View File

@@ -45,7 +45,8 @@ final class IconRuntime implements RuntimeExtensionInterface
$options = $this->mergeWithDefaultOptions($userOptions); $options = $this->mergeWithDefaultOptions($userOptions);
$svg = $this->getSvg($options['icon']); $svg = $this->getSvg($options['icon']);
$svg = $this->sanitiseSvg($svg);
$this->sanitiseSvg($svg);
$colourClasses = $this->getColourClasses($options['colour'], $options['hover']); $colourClasses = $this->getColourClasses($options['colour'], $options['hover']);
$extraClasses = $this->getExtraClasses($options['classes']); $extraClasses = $this->getExtraClasses($options['classes']);
@@ -93,13 +94,12 @@ final class IconRuntime implements RuntimeExtensionInterface
return file_get_contents($iconFilepath); return file_get_contents($iconFilepath);
} }
private function sanitiseSvg(string &$svg): string private function sanitiseSvg(string &$svg): void
{ {
$this->removeExistingTitleElement($svg); $this->removeExistingTitleElement($svg);
$this->removeBlackStrokeAttributes($svg); $this->removeBlackStrokeAttributes($svg);
$this->removeStrokeCurrentColor($svg); $this->removeStrokeCurrentColor($svg);
$this->removeBlackFillAttributes($svg);
return $this->removeBlackFillAttributes($svg);
} }
private function findSvgFilepath(string $iconName): string private function findSvgFilepath(string $iconName): string
@@ -130,9 +130,9 @@ final class IconRuntime implements RuntimeExtensionInterface
$svg = \preg_replace('/stroke=(\'|")currentColor(\'|")/', '', $svg); $svg = \preg_replace('/stroke=(\'|")currentColor(\'|")/', '', $svg);
} }
private function removeBlackFillAttributes(string $content): string private function removeBlackFillAttributes(string &$svg): void
{ {
return preg_replace('/fill(=|:)"?\s*(#0{6}|#000|rgb\(\s*0,\s*0,\s*0\s*\)|black)\s*"?/', '', $content); $svg = preg_replace('/fill(=|:)"?\s*(#0{6}|#000|rgb\(\s*0,\s*0,\s*0\s*\)|black)\s*"?/', '', $svg);
} }
private function getColourClasses(string $primaryColour, ?string $hoverColour): string private function getColourClasses(string $primaryColour, ?string $hoverColour): string