Skip to content

Commit 4c26d37

Browse files
authored
[9.x] Add Conditionable support for callback conditions (#37667)
* Add `Conditionable` support for callback conditions * Update DocBlocks in `Enumerable` to match `Conditionable` * Update uses * Add to collection higher order proxy
1 parent d8f0f04 commit 4c26d37

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

Collection.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,7 @@ public function sole($key = null, $operator = null, $value = null)
10691069
? $this->operatorForWhere(...func_get_args())
10701070
: $key;
10711071

1072-
$items = $this->when($filter)->filter($filter);
1072+
$items = $this->unless($filter == null)->filter($filter);
10731073

10741074
if ($items->isEmpty()) {
10751075
throw new ItemNotFoundException;

Enumerable.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ public function except($keys);
268268
public function filter(callable $callback = null);
269269

270270
/**
271-
* Apply the callback if the value is truthy.
271+
* Apply the callback if the given "value" is (or resolves to) truthy.
272272
*
273273
* @param bool $value
274274
* @param callable|null $callback
@@ -296,7 +296,7 @@ public function whenEmpty(callable $callback, callable $default = null);
296296
public function whenNotEmpty(callable $callback, callable $default = null);
297297

298298
/**
299-
* Apply the callback if the value is falsy.
299+
* Apply the callback if the given "value" is (or resolves to) truthy.
300300
*
301301
* @param bool $value
302302
* @param callable $callback

LazyCollection.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ public function sole($key = null, $operator = null, $value = null)
10281028
: $key;
10291029

10301030
return $this
1031-
->when($filter)
1031+
->unless($filter == null)
10321032
->filter($filter)
10331033
->take(2)
10341034
->collect()

Traits/EnumeratesValues.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,18 @@
3131
* @property-read HigherOrderCollectionProxy $min
3232
* @property-read HigherOrderCollectionProxy $partition
3333
* @property-read HigherOrderCollectionProxy $reject
34+
* @property-read HigherOrderCollectionProxy $skipUntil
35+
* @property-read HigherOrderCollectionProxy $skipWhile
3436
* @property-read HigherOrderCollectionProxy $some
3537
* @property-read HigherOrderCollectionProxy $sortBy
3638
* @property-read HigherOrderCollectionProxy $sortByDesc
37-
* @property-read HigherOrderCollectionProxy $skipUntil
38-
* @property-read HigherOrderCollectionProxy $skipWhile
3939
* @property-read HigherOrderCollectionProxy $sum
4040
* @property-read HigherOrderCollectionProxy $takeUntil
4141
* @property-read HigherOrderCollectionProxy $takeWhile
4242
* @property-read HigherOrderCollectionProxy $unique
43+
* @property-read HigherOrderCollectionProxy $unless
4344
* @property-read HigherOrderCollectionProxy $until
45+
* @property-read HigherOrderCollectionProxy $when
4446
*/
4547
trait EnumeratesValues
4648
{
@@ -76,7 +78,9 @@ trait EnumeratesValues
7678
'takeUntil',
7779
'takeWhile',
7880
'unique',
81+
'unless',
7982
'until',
83+
'when',
8084
];
8185

8286
/**
@@ -138,7 +142,7 @@ public static function times($number, callable $callback = null)
138142
}
139143

140144
return static::range(1, $number)
141-
->when($callback)
145+
->unless($callback == null)
142146
->map($callback);
143147
}
144148

0 commit comments

Comments
 (0)