diff --git a/src/Twig/Component/Badge.php b/src/Twig/Component/Badge.php index 887ca76..bc09ebd 100644 --- a/src/Twig/Component/Badge.php +++ b/src/Twig/Component/Badge.php @@ -24,7 +24,7 @@ final class Badge * @param BadgeableInterface $object The object to be converted into a badge * @param string $class Extra classes you want to add to the badge template */ - public function mount(BadgeableInterface $object, string $class = '', string $colour = null): void + public function mount(?BadgeableInterface $object = null, string $class = '', string $colour = null): void { if (null !== $colour) { @@ -39,6 +39,11 @@ final class Badge $palette = EnumBadge::{$colour}->getPalette(); } else { + + if (null === $object) { + throw new \RuntimeException("You must specify a badge colour If no instance of BadgeableInterface is provided."); + } + $palette = $object->getBadgeColour()->getPalette(); }