Throw if no instance or colour is provided

This commit is contained in:
2024-08-08 15:58:27 +01:00
parent 4d110418fa
commit e6daf6d6b2

View File

@@ -24,7 +24,7 @@ final class Badge
* @param BadgeableInterface $object The object to be converted into a 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 * @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) { if (null !== $colour) {
@@ -39,6 +39,11 @@ final class Badge
$palette = EnumBadge::{$colour}->getPalette(); $palette = EnumBadge::{$colour}->getPalette();
} else { } else {
if (null === $object) {
throw new \RuntimeException("You must specify a badge colour If no instance of BadgeableInterface is provided.");
}
$palette = $object->getBadgeColour()->getPalette(); $palette = $object->getBadgeColour()->getPalette();
} }