From e6daf6d6b283e13f86454aa220d9d643e64109f7 Mon Sep 17 00:00:00 2001 From: Bradley Date: Thu, 8 Aug 2024 15:58:27 +0100 Subject: [PATCH] Throw if no instance or colour is provided --- src/Twig/Component/Badge.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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(); }