From e97ef857effc345d317198c44ec4515044c69491 Mon Sep 17 00:00:00 2001 From: Bradley Date: Tue, 27 Jun 2023 10:03:22 +0100 Subject: [PATCH] Further refactoring --- src/Twig/Runtime/IconRuntime.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Twig/Runtime/IconRuntime.php b/src/Twig/Runtime/IconRuntime.php index f5d679d..1179415 100644 --- a/src/Twig/Runtime/IconRuntime.php +++ b/src/Twig/Runtime/IconRuntime.php @@ -45,7 +45,8 @@ final class IconRuntime implements RuntimeExtensionInterface $options = $this->mergeWithDefaultOptions($userOptions); $svg = $this->getSvg($options['icon']); - $svg = $this->sanitiseSvg($svg); + + $this->sanitiseSvg($svg); $colourClasses = $this->getColourClasses($options['colour'], $options['hover']); $extraClasses = $this->getExtraClasses($options['classes']); @@ -93,13 +94,12 @@ final class IconRuntime implements RuntimeExtensionInterface return file_get_contents($iconFilepath); } - private function sanitiseSvg(string &$svg): string + private function sanitiseSvg(string &$svg): void { $this->removeExistingTitleElement($svg); $this->removeBlackStrokeAttributes($svg); $this->removeStrokeCurrentColor($svg); - - return $this->removeBlackFillAttributes($svg); + $this->removeBlackFillAttributes($svg); } private function findSvgFilepath(string $iconName): string @@ -130,9 +130,9 @@ final class IconRuntime implements RuntimeExtensionInterface $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