From 56c7827af7e4f093037750ca22157e83230c527c Mon Sep 17 00:00:00 2001 From: Aerendir Date: Fri, 27 Sep 2024 09:28:13 +0200 Subject: [PATCH] Fix handling of Drawers. --- src/Manager/InvoicesManager.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Manager/InvoicesManager.php b/src/Manager/InvoicesManager.php index ee41782a..7a9025e9 100644 --- a/src/Manager/InvoicesManager.php +++ b/src/Manager/InvoicesManager.php @@ -77,11 +77,6 @@ public function setSubscription(SubscriptionInterface $subscription): self public function addDrawer(string $name, InvoiceDrawerInterface $drawer): self { - // If this is the default drawer - if ($this->defaultDrawer === $name) { - $this->defaultDrawer = $drawer; - } - $this->drawers[$name] = $drawer; return $this; @@ -98,7 +93,7 @@ public function drawInvoice(InvoiceInterface $invoice, string $drawer = null): a public function getDrawer(string $drawer = null): InvoiceDrawerInterface { // If a Drawer were passed and it exists - if (null !== $drawer && \in_array($drawer, $this->drawers)) { + if (null !== $drawer && \in_array($drawer, array_keys($this->drawers))) { // Use it $drawer = $this->drawers[$drawer]; } @@ -106,12 +101,12 @@ public function getDrawer(string $drawer = null): InvoiceDrawerInterface // If a drawer were not passed... if (null === $drawer) { // ... check for the existence of a default one and it doesn't exist... - if (null === $this->defaultDrawer) { + if (false === is_string($this->defaultDrawer)) { // ... Throw an error throw new \LogicException('To draw an Invoice you have to pass an InvoiceDrawerInterface drawer or either set a default drawer in the features set.'); } - $drawer = $this->defaultDrawer; + $drawer = $this->drawers[$this->defaultDrawer]; } return $drawer;