Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#87 - Allow static macros #88

Merged
merged 2 commits into from
Jul 21, 2023

Conversation

Luke-Shepp
Copy link
Contributor

@Luke-Shepp Luke-Shepp commented Jul 20, 2023

Fixes: #87

Money and Currency override the Macroable __callStatic method, effectively disabling static macros.

To resolve this issue, a check has been added: If the statically called method exists as a macro, then call the macro instead.

Additionally, added Macros and Mixins to the README - currently this functionality is not documented.

Tests:
Screenshot 2023-07-20 at 21 43 19

Example usage:

use Akaunting\Money\Currency;
use Akaunting\Money\Money;

Money::macro(
    'zero', 
    fn (?string $currency = null) => new Money(0, new Currency($currency ?? 'GBP'))
);

$money = Money::zero();

Money and Currency override the Macroable __callStatic
method, effectively disabling static macros.

Add a check in, if the statically called method exists
as a macro, then call the macro instead.
@denisdulici denisdulici merged commit e684359 into akaunting:master Jul 21, 2023
10 checks passed
@denisdulici
Copy link
Member

Thanks for your contribution.

denisdulici added a commit that referenced this pull request Jul 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to macro static methods
2 participants