Extract method
This commit is contained in:
@@ -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>.*<\/title>/', '', $svg);
|
||||
|
||||
Reference in New Issue
Block a user