From 4142c24e003c7fea63d71551bcdd2f29e12f3f8e Mon Sep 17 00:00:00 2001 From: Bradley Date: Tue, 27 Jun 2023 09:55:42 +0100 Subject: [PATCH] Extract method --- src/Twig/Runtime/IconRuntime.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Twig/Runtime/IconRuntime.php b/src/Twig/Runtime/IconRuntime.php index 47e6da6..fa279f8 100644 --- a/src/Twig/Runtime/IconRuntime.php +++ b/src/Twig/Runtime/IconRuntime.php @@ -44,12 +44,14 @@ final class IconRuntime implements RuntimeExtensionInterface { $options = $this->mergeWithDefaultOptions($userOptions); - $svg = $this->getSanitisedIconSvg($options['icon']); + $svg = $this->getSvg($options['icon']); + $svg = $this->sanitiseSvg($svg); $colourClasses = $this->getColourClasses($options['colour'], $options['hover']); $extraClasses = $this->getExtraClasses($options['classes']); - $svg = $this->addClassesToSvg($svg, trim($colourClasses.' '.$extraClasses)); + $classes = trim($colourClasses.' '.$extraClasses); + $svg = $this->addClassesToSvg($svg, $classes); $svg = $this->addTitleToSvgIfNotNull($svg, $options['title']); $svg = $this->setSvgHeightAndWidth($svg, $options['size']); @@ -81,11 +83,14 @@ final class IconRuntime implements RuntimeExtensionInterface } } - private function getSanitisedIconSvg(string $iconName): string + private function getSvg(string $iconName): string { $iconFilepath = $this->findSvgFilepath($iconName); - $svg = $this->getSvgMarkup($iconFilepath); + return file_get_contents($iconFilepath); + } + private function sanitiseSvg(string &$svg): string + { $this->removeExistingTitleElement($svg); $this->removeBlackStrokeAttributes($svg); $this->removeStrokeCurrentColor($svg); @@ -106,11 +111,6 @@ final class IconRuntime implements RuntimeExtensionInterface throw new IconNotFound(sprintf('File "%s.svg" not found in %s', $iconName, implode(', ', $this->directories))); } - private function getSvgMarkup(string $filepath): string - { - return file_get_contents($filepath); - } - private function removeExistingTitleElement(string &$svg): void { $svg = preg_replace('/.*<\/title>/', '', $svg);