Permalink
Browse files

Update `contains` and `first` to match Laravel 5.4 implementation (#61)

  • Loading branch information...
1 parent 83619ce commit b9ea841ad2c679dcf2aed200aca306f57ca9ea56 @besologic besologic committed on GitHub Jan 30, 2017
Showing with 16 additions and 9 deletions.
  1. +16 −9 src/Support/MailThiefCollection.php
@@ -7,25 +7,29 @@
class MailThiefCollection extends Collection
{
/**
- * Identical to the 5.3 implementation of contains
+ * Identical to the 5.4 implementation of contains
*/
public function contains($key, $operator = null, $value = null)
{
- if (func_num_args() == 2) {
- return $this->contains(function ($item) use ($key, $value) {
- return data_get($item, $key) == $value;
- });
+ if (func_num_args() == 1) {
+ if ($this->useAsCallable($key)) {
+ return ! is_null($this->first($key));
+ }
+
+ return in_array($key, $this->items);
}
- if ($this->useAsCallable($key)) {
- return ! is_null($this->first($key));
+ if (func_num_args() == 2) {
+ $value = $operator;
+
+ $operator = '=';
}
- return in_array($key, $this->items);
+ return $this->contains($this->operatorForWhere($key, $operator, $value));
}
/**
- * 5.3 implementation of Arr::first()
+ * 5.4 implementation of Arr::first()
*/
public function first(callable $callback = null, $default = null)
{
@@ -35,15 +39,18 @@ public function first(callable $callback = null, $default = null)
if (empty($array)) {
return value($default);
}
+
foreach ($array as $item) {
return $item;
}
}
+
foreach ($array as $key => $value) {
if (call_user_func($callback, $value, $key)) {
return $value;
}
}
+
return value($default);
}
}

0 comments on commit b9ea841

Please sign in to comment.