Skip to content
This repository was archived by the owner on Mar 14, 2024. It is now read-only.

Commit b9ea841

Browse files
authored
Update contains and first to match Laravel 5.4 implementation (#61)
1 parent 83619ce commit b9ea841

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/Support/MailThiefCollection.php

+16-9
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,29 @@
77
class MailThiefCollection extends Collection
88
{
99
/**
10-
* Identical to the 5.3 implementation of contains
10+
* Identical to the 5.4 implementation of contains
1111
*/
1212
public function contains($key, $operator = null, $value = null)
1313
{
14-
if (func_num_args() == 2) {
15-
return $this->contains(function ($item) use ($key, $value) {
16-
return data_get($item, $key) == $value;
17-
});
14+
if (func_num_args() == 1) {
15+
if ($this->useAsCallable($key)) {
16+
return ! is_null($this->first($key));
17+
}
18+
19+
return in_array($key, $this->items);
1820
}
1921

20-
if ($this->useAsCallable($key)) {
21-
return ! is_null($this->first($key));
22+
if (func_num_args() == 2) {
23+
$value = $operator;
24+
25+
$operator = '=';
2226
}
2327

24-
return in_array($key, $this->items);
28+
return $this->contains($this->operatorForWhere($key, $operator, $value));
2529
}
2630

2731
/**
28-
* 5.3 implementation of Arr::first()
32+
* 5.4 implementation of Arr::first()
2933
*/
3034
public function first(callable $callback = null, $default = null)
3135
{
@@ -35,15 +39,18 @@ public function first(callable $callback = null, $default = null)
3539
if (empty($array)) {
3640
return value($default);
3741
}
42+
3843
foreach ($array as $item) {
3944
return $item;
4045
}
4146
}
47+
4248
foreach ($array as $key => $value) {
4349
if (call_user_func($callback, $value, $key)) {
4450
return $value;
4551
}
4652
}
53+
4754
return value($default);
4855
}
4956
}

0 commit comments

Comments
 (0)