Skip to content

Commit

Permalink
Add support macros (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardogobbosouza authored Apr 24, 2024
1 parent 522d2d6 commit 783b08a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Money.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class Money implements Arrayable, Jsonable, JsonSerializable
use MoneyParserTrait;
use Macroable {
Macroable::__call as macroCall;
Macroable::__callStatic as macroCallStatic;
}

/**
Expand Down Expand Up @@ -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));

Expand Down
5 changes: 5 additions & 0 deletions tests/MoneyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,5 +233,10 @@ public function testMacroable()
'some-return-value',
$money->someMacro()
);

static::assertEquals(
'some-return-value',
Money::someMacro()
);
}
}

0 comments on commit 783b08a

Please sign in to comment.