Skip to content

Commit 34471b4

Browse files
xurshudyanValodia
andauthored
[9.x] Convert closures to arrow functions (#46076)
* formating * Apply fixes from StyleCI --------- Co-authored-by: Valodia <[email protected]>
1 parent 8a71cd3 commit 34471b4

File tree

3 files changed

+10
-26
lines changed

3 files changed

+10
-26
lines changed

src/Illuminate/Collections/Arr.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -838,9 +838,7 @@ public static function where($array, callable $callback)
838838
*/
839839
public static function whereNotNull($array)
840840
{
841-
return static::where($array, function ($value) {
842-
return ! is_null($value);
843-
});
841+
return static::where($array, fn ($value) => ! is_null($value));
844842
}
845843

846844
/**

src/Illuminate/Collections/Collection.php

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,9 @@ public function avg($callback = null)
8484
{
8585
$callback = $this->valueRetriever($callback);
8686

87-
$items = $this->map(function ($value) use ($callback) {
88-
return $callback($value);
89-
})->filter(function ($value) {
90-
return ! is_null($value);
91-
});
87+
$items = $this
88+
->map(fn ($value) => $callback($value))
89+
->filter(fn ($value) => ! is_null($value));
9290

9391
if ($count = $items->count()) {
9492
return $items->sum() / $count;
@@ -349,14 +347,10 @@ public function duplicatesStrict($callback = null)
349347
protected function duplicateComparator($strict)
350348
{
351349
if ($strict) {
352-
return function ($a, $b) {
353-
return $a === $b;
354-
};
350+
return fn ($a, $b) => $a === $b;
355351
}
356352

357-
return function ($a, $b) {
358-
return $a == $b;
359-
};
353+
return fn ($a, $b) => $a == $b;
360354
}
361355

362356
/**
@@ -1633,13 +1627,9 @@ public function values()
16331627
*/
16341628
public function zip($items)
16351629
{
1636-
$arrayableItems = array_map(function ($items) {
1637-
return $this->getArrayableItems($items);
1638-
}, func_get_args());
1630+
$arrayableItems = array_map(fn ($items) => $this->getArrayableItems($items), func_get_args());
16391631

1640-
$params = array_merge([function () {
1641-
return new static(func_get_args());
1642-
}, $this->items], $arrayableItems);
1632+
$params = array_merge([fn () => new static(func_get_args()), $this->items], $arrayableItems);
16431633

16441634
return new static(array_map(...$params));
16451635
}

src/Illuminate/Collections/LazyCollection.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,7 @@ public function except($keys)
430430
public function filter(callable $callback = null)
431431
{
432432
if (is_null($callback)) {
433-
$callback = function ($value) {
434-
return (bool) $value;
435-
};
433+
$callback = fn ($value) => (bool) $value;
436434
}
437435

438436
return new static(function () use ($callback) {
@@ -1500,9 +1498,7 @@ public function takeWhile($value)
15001498
/** @var callable(TValue, TKey): bool $callback */
15011499
$callback = $this->useAsCallable($value) ? $value : $this->equality($value);
15021500

1503-
return $this->takeUntil(function ($item, $key) use ($callback) {
1504-
return ! $callback($item, $key);
1505-
});
1501+
return $this->takeUntil(fn ($item, $key) => ! $callback($item, $key));
15061502
}
15071503

15081504
/**

0 commit comments

Comments
 (0)