• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tempestphp / tempest-framework / 14151138145

28 Mar 2025 10:29PM UTC coverage: 80.716%. Remained the same
14151138145

push

github

web-flow
feat(support): support `$default` on array `first` and `last` methods (#1096)

11 of 12 new or added lines in 2 files covered. (91.67%)

3 existing lines in 1 file now uncovered.

10941 of 13555 relevant lines covered (80.72%)

100.32 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.29
/src/Tempest/Support/src/Arr/ManipulatesArray.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Tempest\Support\Arr;
6

7
use Closure;
8
use Stringable;
9
use Tempest\Support\Str\ImmutableString;
10

11
use function Tempest\Support\tap;
12

13
/**
14
 * @template TKey of array-key
15
 * @template TValue
16
 *
17
 * @implements \ArrayAccess<TKey, TValue>
18
 * @implements \Iterator<TKey, TValue>
19
 */
20
trait ManipulatesArray
21
{
22
    /** @var array<TKey, TValue> */
23
    private(set) array $value;
24

25
    /**
26
     * @param array<TKey, TValue>|self<TKey, TValue>|TValue $input
27
     */
28
    public function __construct(mixed $input = [])
978✔
29
    {
30
        $this->value = namespace\wrap($input);
978✔
31
    }
32

33
    abstract protected function createOrModify(iterable $array): mixed;
34

35
    /**
36
     * Creates an array from the specified `$string`, split by the given `$separator`.
37
     */
38
    public static function explode(string|Stringable $string, string $separator = ' '): static
81✔
39
    {
40
        if ($separator === '') {
81✔
41
            return new static([(string) $string]);
1✔
42
        }
43

44
        if (((string) $string) === '') {
81✔
45
            return new static();
×
46
        }
47

48
        return new static(explode($separator, (string) $string));
81✔
49
    }
50

51
    /**
52
     * Converts various data structures to an instance.
53
     * {@see Traversable} and {@see Countable} instances are converted as well, not just wrapped.
54
     *
55
     * @param mixed $input Any value that can be converted to an array:
56
     *                     - Arrays are returned as-is
57
     *                     - Scalar values are wrapped in an array
58
     *                     - Traversable objects are converted using `{@see iterator_to_array}`
59
     *                     - {@see Countable} objects are converted to arrays
60
     *                     - {@see null} becomes an empty array
61
     */
62
    public static function createFrom(mixed $input): static
×
63
    {
64
        return new static(namespace\to_array($input));
×
65
    }
66

67
    /**
68
     * Finds a value in the array and return the corresponding key if successful.
69
     *
70
     * @param (Closure(TValue, TKey): bool)|mixed $value The value to search for, a Closure will find the first item that returns true.
71
     * @param bool $strict Whether to use strict comparison.
72
     *
73
     * @return array-key|null The key for `$value` if found, `null` otherwise.
74
     */
75
    public function findKey(mixed $value, bool $strict = false): int|string|null
7✔
76
    {
77
        return namespace\find_key($this->value, $value, $strict);
7✔
78
    }
79

80
    /**
81
     * Chunks the array into chunks of the given size.
82
     *
83
     * @param int $size The size of each chunk.
84
     * @param bool $preserveKeys Whether to preserve the keys of the original array.
85
     *
86
     * @return static<array-key, static>
87
     */
88
    public function chunk(int $size, bool $preserveKeys = true): static
4✔
89
    {
90
        return $this->createOrModify(array_map(fn (array $array) => new static($array), namespace\chunk($this->value, $size, $preserveKeys)));
4✔
91
    }
92

93
    /**
94
     * Reduces the array to a single value using a callback.
95
     *
96
     * @template TReduceInitial
97
     * @template TReduceReturnType
98
     *
99
     * @param callable(TReduceInitial|TReduceReturnType, TValue, TKey): TReduceReturnType $callback
100
     * @param TReduceInitial $initial
101
     *
102
     * @return TReduceReturnType
103
     */
104
    public function reduce(callable $callback, mixed $initial = null): mixed
3✔
105
    {
106
        return namespace\reduce($this->value, $callback, $initial);
3✔
107
    }
108

109
    /**
110
     * Shuffles the array.
111
     */
112
    public function shuffle(): static
4✔
113
    {
114
        return $this->createOrModify(namespace\shuffle($this->value));
4✔
115
    }
116

117
    /**
118
     * Removes the specified items from the array.
119
     *
120
     * @param array-key|array<array-key> $keys The keys of the items to remove.
121
     */
122
    public function remove(string|int|array $keys): static
10✔
123
    {
124
        return $this->createOrModify(namespace\remove($this->value, $keys));
10✔
125
    }
126

127
    /**
128
     * Alias of {@see \Tempest\Support\Arr\remove}.
129
     */
130
    public function forget(string|int|array $keys): static
3✔
131
    {
132
        return $this->createOrModify(namespace\remove($this->value, $keys));
3✔
133
    }
134

135
    /**
136
     * Asserts whether the array is a list.
137
     * An array is a list if its keys consist of consecutive numbers.
138
     */
139
    public function isList(): bool
19✔
140
    {
141
        return namespace\is_list($this->value);
19✔
142
    }
143

144
    /**
145
     * Asserts whether the array is a associative.
146
     * An array is associative if its keys do not consist of consecutive numbers.
147
     */
148
    public function isAssociative(): bool
60✔
149
    {
150
        return namespace\is_associative($this->value);
60✔
151
    }
152

153
    /**
154
     * Gets one or a specified number of random values from the array.
155
     *
156
     * @param int $number The number of random values to get.
157
     * @param bool $preserveKey Whether to include the keys of the original array.
158
     *
159
     * @return static<TKey, TValue>|mixed The random values, or a single value if `$number` is 1.
160
     */
161
    public function random(int $number = 1, bool $preserveKey = false): mixed
5✔
162
    {
163
        return namespace\random($this->value, $number, $preserveKey);
5✔
164
    }
165

166
    /**
167
     * Retrieves values from a given key in each sub-array of the current array.
168
     * Optionally, you can pass a second parameter to also get the keys following the same pattern.
169
     *
170
     * @param string $value The key to assign the values from. Supports dot notation.
171
     * @param string|null $key The key to assign the keys from. Supports dot notation.
172
     */
173
    public function pluck(string $value, ?string $key = null): static
5✔
174
    {
175
        return $this->createOrModify(namespace\pluck($this->value, $value, $key));
5✔
176
    }
177

178
    /**
179
     * Prepends the specified values to the array.
180
     *
181
     * @param TValue $values
182
     */
183
    public function prepend(mixed ...$values): static
12✔
184
    {
185
        return $this->createOrModify(namespace\prepend($this->value, ...$values));
12✔
186
    }
187

188
    /**
189
     * Appends the specified values to the instance.
190
     *
191
     * @param TValue $values
192
     */
193
    public function append(mixed ...$values): static
35✔
194
    {
195
        return $this->createOrModify(namespace\append($this->value, ...$values));
35✔
196
    }
197

198
    /**
199
     * Appends the specified value to the array.
200
     *
201
     * @return static<TKey, TValue>
202
     */
203
    public function add(mixed $value): static
9✔
204
    {
205
        return $this->createOrModify(namespace\push($this->value, $value));
9✔
206
    }
207

208
    /**
209
     * @alias of `add`.
210
     */
211
    public function push(mixed $value): static
3✔
212
    {
213
        return $this->createOrModify(namespace\push($this->value, $value));
3✔
214
    }
215

216
    /**
217
     * Pads the array to the specified size with a value.
218
     *
219
     * @return static<TKey, TValue>
220
     */
221
    public function pad(int $size, mixed $value): static
3✔
222
    {
223
        return $this->createOrModify(namespace\pad($this->value, $size, $value));
3✔
224
    }
225

226
    /**
227
     * Reverses the keys and values of the array.
228
     *
229
     * @return static<TValue&array-key, TKey>
230
     */
231
    public function flip(): static
3✔
232
    {
233
        return $this->createOrModify(namespace\flip($this->value));
3✔
234
    }
235

236
    /**
237
     * Returns a new instance with only unique items from the original array.
238
     *
239
     * @param string|null|Closure $key The key to use as the uniqueness criteria in nested arrays.
240
     * @param bool $shouldBeStrict Whether the comparison should be strict, only used when giving a key parameter.
241
     *
242
     * @return static<TKey, TValue>
243
     */
244
    public function unique(null|Closure|string $key = null, bool $shouldBeStrict = false): static
719✔
245
    {
246
        return $this->createOrModify(namespace\unique($this->value, $key, $shouldBeStrict));
719✔
247
    }
248

249
    /**
250
     * Returns a new instance of the array with only the items that are not present in any of the given arrays.
251
     *
252
     * @param array<TKey, TValue>|static<TKey, TValue> ...$arrays
253
     *
254
     * @return static<TKey, TValue>
255
     */
256
    public function diff(array|self ...$arrays): static
3✔
257
    {
258
        return $this->createOrModify(namespace\diff($this->value, ...$arrays));
3✔
259
    }
260

261
    /**
262
     * Returns a new instance of the array with only the items whose keys are not present in any of the given arrays.
263
     *
264
     * @param array<TKey, TValue>|static<TKey, TValue> ...$arrays
265
     *
266
     * @return static<TKey, TValue>
267
     */
268
    public function diffKeys(array|self ...$arrays): static
3✔
269
    {
270
        return $this->createOrModify(namespace\diff_keys($this->value, ...$arrays));
3✔
271
    }
272

273
    /**
274
     * Returns a new instance of the array with only the items that are present in all of the given arrays.
275
     *
276
     * @param array<TKey, TValue>|static<TKey, TValue> ...$arrays
277
     *
278
     * @return static<TKey, TValue>
279
     */
280
    public function intersect(array|self ...$arrays): static
7✔
281
    {
282
        return $this->createOrModify(namespace\intersect($this->value, ...$arrays));
7✔
283
    }
284

285
    /**
286
     * Returns a new instance of the array with only the items whose keys are present in all of the given arrays.
287
     *
288
     * @param array<TKey, TValue>|static<TKey, TValue> ...$arrays
289
     *
290
     * @return static<TKey, TValue>
291
     */
292
    public function intersectKeys(array|self ...$arrays): static
3✔
293
    {
294
        return $this->createOrModify(namespace\intersect_keys($this->value, ...$arrays));
3✔
295
    }
296

297
    /**
298
     * Merges the array with the given arrays.
299
     *
300
     * @param array<TKey, TValue>|static<TKey, TValue> ...$arrays The arrays to merge.
301
     *
302
     * @return static<TKey, TValue>
303
     */
304
    public function merge(iterable ...$arrays): static
4✔
305
    {
306
        return $this->createOrModify(namespace\merge($this->value, ...$arrays));
4✔
307
    }
308

309
    /**
310
     * Creates a new array with this current array values as keys and the given values as values.
311
     *
312
     * @template TCombineValue
313
     *
314
     * @param array<array-key, TCombineValue>|static<array-key, TCombineValue> $values
315
     *
316
     * @return static<array-key, TCombineValue>
317
     */
318
    public function combine(array|self $values): static
4✔
319
    {
320
        return $this->createOrModify(namespace\combine($this->value, $values));
4✔
321
    }
322

323
    /**
324
     * Asserts whether this instance is equal to the given array.
325
     */
326
    public function equals(array|self $other): bool
94✔
327
    {
328
        return namespace\equals($this->value, $other);
94✔
329
    }
330

331
    /**
332
     * Returns the first item in the instance that matches the given `$filter`.
333
     * If `$filter` is `null`, returns the first item.
334
     *
335
     * @param null|Closure(TValue $value, TKey $key): bool $filter
336
     *
337
     * @return TValue
338
     */
339
    public function first(?Closure $filter = null, mixed $default = null): mixed
166✔
340
    {
341
        return namespace\first($this->value, $filter, $default);
166✔
342
    }
343

344
    /**
345
     * Returns the last item in the instance that matches the given `$filter`.
346
     * If `$filter` is `null`, returns the last item.
347
     *
348
     * @param null|Closure(TValue $value, TKey $key): bool $filter
349
     *
350
     * @return TValue
351
     */
352
    public function last(?Closure $filter = null, mixed $default = null): mixed
2✔
353
    {
354
        return namespace\last($this->value, $filter, $default);
2✔
355
    }
356

357
    /**
358
     * Returns the item at the given index in the specified array.
359
     * @alias of `at()`
360
     *
361
     * @return TValue
362
     */
363
    public function nth(int $index, mixed $default = null): mixed
11✔
364
    {
365
        return $this->at($index, $default);
11✔
366
    }
367

368
    /**
369
     * Returns the item at the given index in the specified array.
370
     *
371
     * @return TValue
372
     */
373
    public function at(int $index, mixed $default = null): mixed
11✔
374
    {
375
        return namespace\at($this->value, $index, $default);
11✔
376
    }
377

378
    /**
379
     * Returns an instance of the array without the last value.
380
     *
381
     * @param mixed $value The popped value will be stored in this variable
382
     */
383
    public function pop(mixed &$value = null): static
3✔
384
    {
385
        return $this->createOrModify(namespace\pop($this->value, $value));
3✔
386
    }
387

388
    /**
389
     * Returns an instance of the array without the first value.
390
     *
391
     * @param mixed $value The unshifted value will be stored in this variable
392
     */
393
    public function unshift(mixed &$value = null): static
3✔
394
    {
395
        return $this->createOrModify(namespace\unshift($this->value, $value));
3✔
396
    }
397

398
    /**
399
     * Returns a new instance of the array in reverse order.
400
     */
401
    public function reverse(): static
3✔
402
    {
403
        return $this->createOrModify(namespace\reverse($this->value));
3✔
404
    }
405

406
    /**
407
     * Asserts whether the array is empty.
408
     */
409
    public function isEmpty(): bool
87✔
410
    {
411
        return namespace\is_empty($this->value);
87✔
412
    }
413

414
    /**
415
     * Asserts whether the array is not empty.
416
     */
417
    public function isNotEmpty(): bool
77✔
418
    {
419
        return ! $this->isEmpty();
77✔
420
    }
421

422
    /**
423
     * Returns an instance of {@see \Tempest\Support\Str\ImmutableString} with the values of the instance joined with the given `$glue`.
424
     */
425
    public function implode(string $glue): ImmutableString
343✔
426
    {
427
        return namespace\implode($this->value, $glue);
343✔
428
    }
429

430
    /**
431
     * Returns a new instance with the keys of this array as values.
432
     *
433
     * @return static<array-key, TKey>
434
     */
435
    public function keys(): static
82✔
436
    {
437
        return $this->createOrModify(namespace\keys($this->value));
82✔
438
    }
439

440
    /**
441
     * Returns a new instance of this array without its keys.
442
     *
443
     * @return static<int, TValue>
444
     */
445
    public function values(): static
734✔
446
    {
447
        return $this->createOrModify(namespace\values($this->value));
734✔
448
    }
449

450
    /**
451
     * Returns a new instance of this array with only the items that pass the given `$filter`.
452
     * If `$filter` is `null`, the new instance will contain only values that are not `false` or `null`.
453
     *
454
     * @param null|Closure(mixed $value, mixed $key): bool $filter
455
     */
456
    public function filter(?Closure $filter = null): static
748✔
457
    {
458
        return $this->createOrModify(namespace\filter($this->value, $filter));
748✔
459
    }
460

461
    /**
462
     * Applies the given callback to all items of the instance.
463
     *
464
     * @param Closure(mixed $value, mixed $key): void $each
465
     */
466
    public function each(Closure $each): static
94✔
467
    {
468
        return $this->createOrModify(namespace\each($this->value, $each));
94✔
469
    }
470

471
    /**
472
     * Returns a new instance of the array, with each item transformed by the given callback.
473
     *
474
     * @template TMapValue
475
     *
476
     * @param  Closure(TValue, TKey): TMapValue $map
477
     *
478
     * @return static<TKey, TMapValue>
479
     */
480
    public function map(Closure $map): static
773✔
481
    {
482
        return $this->createOrModify(namespace\map_iterable($this->value, $map));
773✔
483
    }
484

485
    /**
486
     * Returns a new instance of the array, with each item transformed by the given callback.
487
     * The callback must return a generator, associating a key and a value.
488
     *
489
     * ### Example
490
     * ```php
491
     * arr(['a', 'b'])->mapWithKeys(fn (mixed $value, mixed $key) => yield $key => $value);
492
     * ```
493
     *
494
     * @param Closure(mixed $value, mixed $key): \Generator $map
495
     */
496
    public function mapWithKeys(Closure $map): static
84✔
497
    {
498
        return $this->createOrModify(namespace\map_with_keys($this->value, $map));
84✔
499
    }
500

501
    /**
502
     * Gets the value identified by the specified `$key`, or `$default` if no such value exists.
503
     *
504
     * @return mixed|ImmutableArray
505
     */
506
    public function get(int|string $key, mixed $default = null): mixed
717✔
507
    {
508
        return get_by_key($this->value, $key, $default);
717✔
509
    }
510

511
    /**
512
     * Associates the given `$value` to the given `$key` on the instance.
513
     */
514
    public function set(string $key, mixed $value): static
4✔
515
    {
516
        return $this->createOrModify(set_by_key($this->value, $key, $value));
4✔
517
    }
518

519
    /**
520
     * @alias of `set`
521
     */
522
    public function put(string $key, mixed $value): static
3✔
523
    {
524
        return $this->createOrModify(set_by_key($this->value, $key, $value));
3✔
525
    }
526

527
    /**
528
     * Asserts whether a value identified by the specified `$key` exists.
529
     */
530
    public function has(int|string $key): bool
18✔
531
    {
532
        return namespace\has($this->value, $key);
18✔
533
    }
534

535
    /**
536
     * Asserts whether the instance contains an item that can be identified by `$search`.
537
     */
538
    public function contains(mixed $search): bool
50✔
539
    {
540
        return namespace\contains($this->value, $search);
50✔
541
    }
542

543
    /**
544
     * Asserts whether all items in the instance pass the given `$callback`.
545
     *
546
     * @param Closure(TValue, TKey): bool $callback
547
     *
548
     * @return bool If the collection is empty, returns `true`.
549
     */
550
    public function every(?Closure $callback = null): bool
4✔
551
    {
552
        return namespace\every($this->value, $callback);
4✔
553
    }
554

555
    /**
556
     * Converts the dot-notation keys of the instance to a set of nested arrays.
557
     */
558
    public function undot(): static
155✔
559
    {
560
        return $this->createOrModify(namespace\undot($this->value));
155✔
561
    }
562

563
    /**
564
     * Returns a copy of the array that converts nested arrays to a single-dimension dot-notation array.
565
     */
566
    public function dot(): static
10✔
567
    {
568
        return $this->createOrModify(namespace\dot($this->value));
10✔
569
    }
570

571
    /**
572
     * Joins all values using the specified `$glue`. The last item of the string is separated by `$finalGlue`.
573
     */
574
    public function join(string $glue = ', ', ?string $finalGlue = ' and '): ImmutableString
24✔
575
    {
576
        return namespace\join($this->value, $glue, $finalGlue);
24✔
577
    }
578

579
    /**
580
     * Groups the array by the results of the provided keyExtractor.
581
     *
582
     * @param Closure(TValue, TKey): array-key $keyExtractor
583
     */
584
    public function groupBy(Closure $keyExtractor): static
1✔
585
    {
586
        return $this->createOrModify(namespace\group_by($this->value, $keyExtractor));
1✔
587
    }
588

589
    /**
590
     * Flattens the instance to a single-level array, or until the specified `$depth` is reached.
591
     *
592
     * ### Example
593
     * ```php
594
     * arr(['foo', ['bar', 'baz']])->flatten(); // ['foo', 'bar', 'baz']
595
     * ```
596
     */
597
    public function flatten(int|float $depth = INF): static
710✔
598
    {
599
        return $this->createOrModify(namespace\flatten($this->value, $depth));
710✔
600
    }
601

602
    /**
603
     * Returns a new instance of the array, with each item transformed by the given callback, then flattens it by the specified depth.
604
     *
605
     * @template TMapValue
606
     *
607
     * @param  Closure(TValue, TKey): TMapValue[] $map
608
     *
609
     * @return static<TKey, TMapValue>
610
     */
611
    public function flatMap(Closure $map, int|float $depth = 1): static
21✔
612
    {
613
        return $this->createOrModify(namespace\flat_map($this->value, $map, $depth));
21✔
614
    }
615

616
    /**
617
     * Maps the items of the instance to the given object.
618
     *
619
     * @see \Tempest\map()
620
     *
621
     * @template T
622
     * @param class-string<T> $to
623
     * @return static<int,T>
624
     */
625
    public function mapTo(string $to): static
1✔
626
    {
627
        return $this->createOrModify(namespace\map_to($this->value, $to));
1✔
628
    }
629

630
    /**
631
     * Maps the first item of the instance to the given object.
632
     *
633
     * @see \Tempest\map()
634
     *
635
     * @template T
636
     * @param class-string<T> $to
637
     * @return T
638
     */
639
    public function mapFirstTo(string $to): mixed
1✔
640
    {
641
        return \Tempest\map($this->first())->to($to);
1✔
642
    }
643

644
    /**
645
     * Maps the last item of the instance to the given object.
646
     *
647
     * @see \Tempest\map()
648
     *
649
     * @template T
650
     * @param class-string<T> $to
651
     * @return T
652
     */
653
    public function mapLastTo(string $to): mixed
1✔
654
    {
655
        return \Tempest\map($this->last())->to($to);
1✔
656
    }
657

658
    /**
659
     * Returns a new instance of this array sorted by its values.
660
     *
661
     * @param bool $desc Sorts in descending order if `true`; defaults to `false` (ascending).
662
     * @param bool|null $preserveKeys Preserves array keys if `true`; reindexes numerically if `false`.
663
     *                                Defaults to `null`, which auto-detects preservation based on array type  (associative or list).
664
     * @param int $flags Sorting flags to define comparison behavior, defaulting to `SORT_REGULAR`.
665
     * @return static<array-key, TValue> Key type depends on whether array keys are preserved or not.
666
     */
667
    public function sort(bool $desc = false, ?bool $preserveKeys = null, int $flags = SORT_REGULAR): static
12✔
668
    {
669
        return $this->createOrModify(namespace\sort($this->value, $desc, $preserveKeys, $flags));
12✔
670
    }
671

672
    /**
673
     * Returns a new instance of this array sorted by its values using a callback function.
674
     *
675
     * @param callable $callback The function to use for comparing values. It should accept two parameters
676
     *                           and return an integer less than, equal to, or greater than zero if the
677
     *                           first argument is considered to be respectively less than, equal to, or
678
     *                           greater than the second.
679
     * @param bool|null $preserveKeys Preserves array keys if `true`; reindexes numerically if `false`.
680
     *                                Defaults to `null`, which auto-detects preservation based on array type  (associative or list).
681
     * @return static<array-key, TValue> Key type depends on whether array keys are preserved or not.
682
     */
683
    public function sortByCallback(callable $callback, ?bool $preserveKeys = null): static
708✔
684
    {
685
        return $this->createOrModify(namespace\sort_by_callback($this->value, $callback, $preserveKeys));
708✔
686
    }
687

688
    /**
689
     * Returns a new instance of this array sorted by its keys.
690
     *
691
     * @param bool $desc Sorts in descending order if `true`; defaults to `false` (ascending).
692
     * @param int $flags Sorting flags to define comparison behavior, defaulting to `SORT_REGULAR`.
693
     * @return static<TKey, TValue>
694
     */
695
    public function sortKeys(bool $desc = false, int $flags = SORT_REGULAR): static
3✔
696
    {
697
        return $this->createOrModify(namespace\sort_keys($this->value, $desc, $flags));
3✔
698
    }
699

700
    /**
701
     * Returns a new instance of this array sorted by its keys using a callback function.
702
     *
703
     * @param callable $callback The function to use for comparing keys. It should accept two parameters
704
     *                           and return an integer less than, equal to, or greater than zero if the
705
     *                           first argument is considered to be respectively less than, equal to, or
706
     *                           greater than the second.
707
     * @return static<TKey, TValue>
708
     */
709
    public function sortKeysByCallback(callable $callback): static
1✔
710
    {
711
        return $this->createOrModify(namespace\sort_keys_by_callback($this->value, $callback));
1✔
712
    }
713

714
    /**
715
     * Extracts a part of the instance.
716
     *
717
     * ### Example
718
     * ```php
719
     * arr([1, 2, 3, 4, 5])->slice(2); // [3, 4, 5]
720
     * ```
721
     */
722
    public function slice(int $offset, ?int $length = null): static
8✔
723
    {
724
        return $this->createOrModify(namespace\slice($this->value, $offset, $length));
8✔
725
    }
726

727
    /**
728
     * Executes callback with the given `$value` and returns the same `$value`.
729
     *
730
     * @param (Closure(static): void) $callback
731
     */
732
    public function tap(Closure $callback): static
1✔
733
    {
734
        tap($this, $callback);
1✔
735

736
        return $this;
1✔
737
    }
738

739
    /**
740
     * Dumps the instance.
741
     */
UNCOV
742
    public function dump(mixed ...$dumps): static
×
743
    {
UNCOV
744
        lw($this->value, ...$dumps);
×
745

UNCOV
746
        return $this;
×
747
    }
748

749
    /**
750
     * Dumps the instance and stops the execution of the script.
751
     */
752
    public function dd(mixed ...$dd): void
×
753
    {
754
        ld($this->value, ...$dd);
×
755
    }
756

757
    /**
758
     * Returns the underlying array of the instance.
759
     *
760
     * @return array<TKey, TValue>
761
     */
762
    public function toArray(): array
838✔
763
    {
764
        return $this->value;
838✔
765
    }
766
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc