From 783b08a9b5eae97617e66d56375260cb3caa8e96 Mon Sep 17 00:00:00 2001 From: Ricardo Gobbo de Souza Date: Wed, 24 Apr 2024 16:54:44 -0300 Subject: [PATCH] Add support macros (#162) --- src/Money.php | 5 +++++ tests/MoneyTest.php | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/Money.php b/src/Money.php index bd30a9d..810bd0b 100644 --- a/src/Money.php +++ b/src/Money.php @@ -49,6 +49,7 @@ class Money implements Arrayable, Jsonable, JsonSerializable use MoneyParserTrait; use Macroable { Macroable::__call as macroCall; + Macroable::__callStatic as macroCallStatic; } /** @@ -231,6 +232,10 @@ public static function convert(\Money\Money $instance) */ public static function __callStatic($method, array $arguments) { + if (static::hasMacro($method)) { + return static::macroCallStatic($method, $arguments); + } + if (in_array($method, ['min', 'max', 'avg', 'sum'])) { $result = call_user_func_array([\Money\Money::class, $method], static::getArguments($arguments)); diff --git a/tests/MoneyTest.php b/tests/MoneyTest.php index ebeb860..347cbe8 100644 --- a/tests/MoneyTest.php +++ b/tests/MoneyTest.php @@ -233,5 +233,10 @@ public function testMacroable() 'some-return-value', $money->someMacro() ); + + static::assertEquals( + 'some-return-value', + Money::someMacro() + ); } }