-
Notifications
You must be signed in to change notification settings - Fork 11.8k
[12.x] Add Collection::containsManyItems() method
#58312
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -735,6 +735,21 @@ public function containsOneItem(?callable $callback = null): bool | |||||||||||||||||
| return $this->count() === 1; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| /** | ||||||||||||||||||
| * Determine if the collection contains multiple items. If a callback is provided, determine if multiple items match the condition. | ||||||||||||||||||
| * | ||||||||||||||||||
| * @param (callable(TValue, TKey): bool)|null $callback | ||||||||||||||||||
| * @return bool | ||||||||||||||||||
| */ | ||||||||||||||||||
| public function containsManyItems(?callable $callback = null): bool | ||||||||||||||||||
| { | ||||||||||||||||||
| if ($callback) { | ||||||||||||||||||
| return $this->filter($callback)->count() > 1; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| return $this->count() > 1; | ||||||||||||||||||
|
||||||||||||||||||
| public function containsOneItem(?callable $callback = null): bool | |
| { | |
| if ($callback) { | |
| return $this->filter($callback)->count() === 1; | |
| } | |
| return $this->count() === 1; | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it would make sense to add an assertion here and in the two corresponding methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I followed suit with the
containsOneItemmethod doc block:framework/src/Illuminate/Collections/Collection.php
Lines 723 to 736 in cc03bd4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nobody said, there wasn't room for improvement. With this argument, we'd be stuck in the stone age forever.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol easy -- its a doc block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's more than a comment. It improves static analysis.