Skip to content

Commit

Permalink
Style(web-twig): Fix PHPStan issue with adding SimpleXMLElement
Browse files Browse the repository at this point in the history
  * Cannot call method addAttribute() on SimpleXMLElement|null.
  • Loading branch information
literat committed Dec 12, 2023
1 parent 08822a4 commit b8a89f9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/web-twig/src/Twig/SvgExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,11 @@ private function makeReusableSVG(string $iconId, SimpleXMLElement $regularSvg)
}
}

$reuseSvg->addChild('use')->addAttribute('href', '#' . $iconId);
$reuseSvgWithUseElement = $reuseSvg->addChild('use');

if ($reuseSvgWithUseElement instanceof SimpleXMLElement) {
$reuseSvgWithUseElement->addAttribute('href', '#' . $iconId);
}
} elseif ($key !== self::ATTR_VIEWBOX) {
$reuseSvg->addAttribute((string) $key, (string) $value);
}
Expand Down

0 comments on commit b8a89f9

Please sign in to comment.