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

[10.x] Add percentage method to Collections #48034

Merged
merged 3 commits into from Aug 11, 2023

Conversation

WendellAdriel
Copy link
Contributor

Changes

In this PR I add a new method called percentage to the Collections that allows us to calculate the percentage in a collection based on a truth test.

Why

In many apps, we need to calculate percentage values of collections for something, especially when dealing with reports, analytics, metrics etc. Although that's something easy to calculate, doing it manually every time depending on the type of application we build is tiresome.

This method is just a life improvement for the DX, so we don't need to calculate that every time we need.

@WendellAdriel
Copy link
Contributor Author

I saw that there's one failing check, but I checked the details and it doesn't seem to be related to the changes of the PR. There are also 2 other checks that were cancelled but IDK why. Should I do anything about these?

@WendellAdriel
Copy link
Contributor Author

@cosmastech I updated the PR regarding your observation and also added some more test cases to cover when the percentage should be 0 or null.

@taylorotwell taylorotwell merged commit e95dc82 into laravel:10.x Aug 11, 2023
20 checks passed
@WendellAdriel WendellAdriel deleted the collections-percentage branch August 11, 2023 15:27
@WendellAdriel
Copy link
Contributor Author

Thank you so much for merging this @taylorotwell!!!
I forgot about the Enumerable Trait and duplicated the code 😅
Thanks for fixing that!!! 🔥

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.

None yet

3 participants