Skip to content

Commit 75a3c33

Browse files
Fix: allow macro calls on the ReceiptPrinter class
The original ReceiptPrinter class overrides Macroable::__call() keeping any macros from being executed, as an InvalidArgumentException will always be thrown. I fixed this by calling the traits orignal __call() method after checking for existing methods on the printer class.
1 parent da10a28 commit 75a3c33

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/Receipts/ReceiptPrinter.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@
4242
class ReceiptPrinter
4343
{
4444
use Conditionable;
45-
use Macroable;
45+
use Macroable {
46+
Macroable::__call as __macroCall;
47+
}
4648

4749
protected DummyPrintConnector $connector;
4850

@@ -68,15 +70,15 @@ public function __toString(): string
6870
return $this->connector->getData();
6971
}
7072

71-
public function __call($name, $arguments)
73+
public function __call($method, $parameters)
7274
{
73-
if (method_exists($this->printer, $name)) {
74-
$this->printer->{$name}(...$arguments);
75+
if (method_exists($this->printer, $method)) {
76+
$this->printer->{$method}(...$parameters);
7577

7678
return $this;
7779
}
7880

79-
throw new InvalidArgumentException("Method [{$name}] not found on receipt printer object.");
81+
return $this->__macroCall($method, $parameters);
8082
}
8183

8284
public function centerAlign(): self

0 commit comments

Comments
 (0)