Skip to content

Add support for Money based formatters - new - #105

Merged
BenMorel merged 11 commits into
brick:masterfrom
mklepaczewski:feat/money-formatter2
Jan 20, 2026
Merged

BenMorel merged 11 commits into
brick:masterfrom
mklepaczewski:feat/money-formatter2

Conversation

@mklepaczewski

Copy link
Copy Markdown
Contributor

Replaces #103

Summary

  • Added MoneyFormatter interface with a single MoneyFormatter::format(Money $money) : string method
  • Deprecated Money::formatWith() and Money::formatTo()
  • Added basic MoneyLocaleFormatter and MoneyNumberFormatter to replace Money::formatWith() and Money::formatTo()
  • Added tests

Notes

  • I left original tests for Money::formatWith() and Money::formatTo(). I assume these tests should be removed together with the methods
  • tests for MoneyNumberFormatter and MoneyLocaleFormatter are almost copy-pasted from Money::formatWith() and Money::formatTo()
  • I decided not to use MoneyNumberFormatter in MoneyLocaleFormatter as it led to a weird design where the scale used by MoneyNumberFormatter is manipulated from MoneyLocaleFormatter::format()

Comment thread src/Money.php Outdated
Comment on lines +698 to +699
* @deprecated Use MoneyLocaleFormatter::format($money).
*

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we should keep a Money::format() method, that does what formatTo() does currently. Can you please add it? We'll then deprecate formatTo() in favour of format().

Suggested change
* @deprecated Use MoneyLocaleFormatter::format($money).
*
* @deprecated Use Money::format().
*

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, but I don't know if that's what you had in mind. Feel free to elaborate, and I'll make adjustments.

  • I restored the old Money::formatTo().
  • Since Money::formatTo() has been restored to the old form, I also restored Money::formatWith() . It feels right as Money::formatTo() calls Money::formatWith().
  • I added Money::format().

Comment thread src/MoneyLocaleFormatter.php Resolved
Comment thread src/MoneyLocaleFormatter.php Resolved
Comment thread src/Money.php Resolved
Comment thread src/Money.php Resolved
Comment thread src/Money.php Resolved
Comment thread tests/MoneyTest.php Resolved
Comment thread src/MoneyLocaleFormatter.php Resolved
@mklepaczewski

Copy link
Copy Markdown
Contributor Author

@BenMorel, I applied all the suggested fixes.

@BenMorel
BenMorel merged commit 7d28018 into brick:master Jan 20, 2026
7 checks passed
@BenMorel

Copy link
Copy Markdown
Member

Thank you, @mklepaczewski!

@BenMorel

Copy link
Copy Markdown
Member

@mklepaczewski FYI, I moved formatters to the Formatter namespace, to align with what was done for ExchangeRateProvider!

@BenMorel

Copy link
Copy Markdown
Member

Released in 0.11.0.

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.

2 participants