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

allocateWithRemainder() performs no allocation #68

Open
ghost opened this issue Oct 26, 2022 · 4 comments
Open

allocateWithRemainder() performs no allocation #68

ghost opened this issue Oct 26, 2022 · 4 comments

Comments

@ghost
Copy link

ghost commented Oct 26, 2022

Prior to this change, Money::of('1', 'USD')->allocateWithRemainder(400, 0, 40, 20, 2) returned 86, 0, 8, 4, 0, 2 (as cents wrapped in Money instances of course), and I distributed the 2 cents remainder by adding one to the 86 figure, one to the 8 figure.

After the change, Money::of('1', 'USD')->allocateWithRemainder(400, 0, 40, 20, 2) returns 0, 0, 0, 0, 0, 100.

I understand the reason behind this, however allocateWithRemainder() is no longer helpful in cases like the above, as it does no allocation at all.

Is there anything within the library that can help me with that? Or should I resort to allocating the 100 cents myself (probably by weight)?

Thanks!

@BenMorel
Copy link
Member

Hi, I did not think that the previous behaviour could be useful, sorry for "fixing" it!

One solution I can see is to provide both behaviours, either under different method names, or behind a flag. I'm open to suggestions regarding naming!

Maybe even both implementations could be merged into allocate(), which would now have 3 possible behaviours depending on a flag... although this can become quickly messy.

In the meantime, I guess you could just copy the old implementation in your own codebase?

@ghost
Copy link
Author

ghost commented Oct 31, 2022

Thanks Ben, I'll stay on v0.5.3 for now, but will look into replicating the old implementation in my own codebase as you suggested. 👍

@BenMorel
Copy link
Member

BenMorel commented Nov 1, 2022

I'd like to re-introduce the old behaviour in some form though, do you know how we could name the old and the new behaviour?

@ghost
Copy link
Author

ghost commented Feb 1, 2023

Sorry for the late reply, I ended up adding the needed functionality in an external helper named apportion(Money $amount, array $ratios): array as the definition of "apportion" seemed fitting for the purpose. 👍

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

No branches or pull requests

1 participant