Passed
Pull Request — master (#306)
by Pol
03:58 queued 01:52
created

CollectionDecorator::empty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace loophp\collection;
6
7
use Closure;
8
use Doctrine\Common\Collections\Criteria;
9
use Generator;
10
use loophp\collection\Contract\Collection as CollectionInterface;
11
use loophp\collection\Contract\Operation;
12
use Psr\Cache\CacheItemPoolInterface;
13
use Traversable;
14
15
use const INF;
16
use const PHP_INT_MAX;
17
18
/**
19
 * @template TKey
20
 * @template T
21
 *
22
 * @immutable
23
 *
24
 * @psalm-consistent-constructor
25
 *
26
 * @psalm-consistent-templates
27
 *
28
 * @implements \loophp\collection\Contract\Collection<TKey, T>
29
 */
30
abstract class CollectionDecorator implements CollectionInterface
31
{
32
    /**
33
     * @param CollectionInterface<TKey, T> $innerCollection
34
     */
35 347
    public function __construct(protected CollectionInterface $innerCollection)
36
    {
37 347
    }
38
39 5
    public function all(bool $normalize = true): array
40
    {
41 5
        return $this->innerCollection->all($normalize);
42
    }
43
44 1
    public function append(mixed ...$items): static
45
    {
46 1
        return new static($this->innerCollection->append(...$items));
47
    }
48
49 2
    public function apply(callable ...$callbacks): static
50
    {
51 2
        return new static($this->innerCollection->apply(...$callbacks));
52
    }
53
54 2
    public function associate(
55
        ?callable $callbackForKeys = null,
56
        ?callable $callbackForValues = null
57
    ): static {
58 2
        return new static($this->innerCollection->associate($callbackForKeys, $callbackForValues));
59
    }
60
61 1
    public function asyncMap(callable $callback): static
62
    {
63 1
        return new static($this->innerCollection->asyncMap($callback));
64
    }
65
66 1
    public function asyncMapN(callable ...$callbacks): static
67
    {
68 1
        return new static($this->innerCollection->asyncMapN(...$callbacks));
69
    }
70
71 2
    public function averages(): static
72
    {
73 2
        return new static($this->innerCollection->averages());
74
    }
75
76 1
    public function cache(?CacheItemPoolInterface $cache = null): static
77
    {
78 1
        return new static($this->innerCollection->cache($cache));
79
    }
80
81 4
    public function chunk(int ...$sizes): static
82
    {
83 4
        return new static($this->innerCollection->chunk(...$sizes));
84
    }
85
86 2
    public function coalesce(): static
87
    {
88 2
        return new static($this->innerCollection->coalesce());
89
    }
90
91 2
    public function collapse(): static
92
    {
93 2
        return new static($this->innerCollection->collapse());
94
    }
95
96 3
    public function column(mixed $column): static
97
    {
98 3
        return new static($this->innerCollection->column($column));
99
    }
100
101 3
    public function combinate(?int $length = null): static
102
    {
103 3
        return new static($this->innerCollection->combinate($length));
104
    }
105
106 3
    public function combine(mixed ...$keys): static
107
    {
108 3
        return new static($this->innerCollection->combine(...$keys));
109
    }
110
111 2
    public function compact(mixed ...$values): static
112
    {
113 2
        return new static($this->innerCollection->compact(...$values));
114
    }
115
116 5
    public function compare(callable $comparator, $default = null): mixed
117
    {
118 5
        return $this->innerCollection->compare($comparator, $default);
119
    }
120
121 5
    public function contains(mixed ...$values): bool
122
    {
123 5
        return $this->innerCollection->contains(...$values);
124
    }
125
126 3
    public function countIn(int &$counter): CollectionInterface
127
    {
128 3
        $this->innerCollection->countIn($counter);
129
130
        return $this;
131 1
    }
132
133 1
    public function current(int $index = 0, $default = null): mixed
134
    {
135
        return $this->innerCollection->current($index, $default);
136 7
    }
137
138 7
    public function cycle(): static
139
    {
140
        return new static($this->innerCollection->cycle());
141 2
    }
142
143 2
    public function diff(mixed ...$values): static
144
    {
145
        return new static($this->innerCollection->diff(...$values));
146 6
    }
147
148 6
    public function diffKeys(mixed ...$keys): static
149
    {
150
        return new static($this->innerCollection->diffKeys(...$keys));
151 2
    }
152
153 2
    public function distinct(?callable $comparatorCallback = null, ?callable $accessorCallback = null): static
154
    {
155
        return new static($this->innerCollection->distinct($comparatorCallback, $accessorCallback));
156 2
    }
157
158 2
    public function drop(int $count): static
159
    {
160
        return new static($this->innerCollection->drop($count));
161 2
    }
162
163 2
    public function dropWhile(callable ...$callbacks): static
164
    {
165
        return new static($this->innerCollection->dropWhile(...$callbacks));
166 5
    }
167
168 5
    public function dump(string $name = '', int $size = 1, ?Closure $closure = null): static
169
    {
170
        return new static($this->innerCollection->dump($name, $size, $closure));
171 1
    }
172
173 1
    public function duplicate(?callable $comparatorCallback = null, ?callable $accessorCallback = null): static
174
    {
175
        return new static($this->innerCollection->duplicate($comparatorCallback, $accessorCallback));
176 18
    }
177
178 18
    public static function empty(): static
179
    {
180
        return new static(Collection::empty());
181 8
    }
182
183 8
    public function equals(iterable $other): bool
184
    {
185
        return $this->innerCollection->equals($other);
186 1
    }
187
188 1
    public function every(callable ...$callbacks): bool
189
    {
190
        return $this->innerCollection->every(...$callbacks);
191 4
    }
192
193 4
    public function explode(mixed ...$explodes): static
194
    {
195
        return new static($this->innerCollection->explode(...$explodes));
196 4
    }
197
198 4
    public function falsy(): bool
199
    {
200
        return $this->innerCollection->falsy();
201 5
    }
202
203 5
    public function filter(callable ...$callbacks): static
204
    {
205
        return new static($this->innerCollection->filter(...$callbacks));
206 5
    }
207
208 5
    public function find($default = null, callable ...$callbacks): mixed
209
    {
210
        return $this->innerCollection->find($default, ...$callbacks);
211 7
    }
212
213 7
    public function first($default = null): mixed
214
    {
215
        return $this->innerCollection->first($default);
216 3
    }
217
218 3
    public function flatMap(callable $callback): static
219
    {
220
        return new static($this->innerCollection->flatMap($callback));
221 2
    }
222
223 2
    public function flatten(int $depth = PHP_INT_MAX): static
224
    {
225
        return new static($this->innerCollection->flatten($depth));
226 4
    }
227
228 4
    public function flip(): static
229
    {
230
        return new static($this->innerCollection->flip());
231 2
    }
232
233 2
    public function foldLeft(callable $callback, $initial): mixed
234
    {
235
        return $this->innerCollection->foldLeft($callback, $initial);
236 1
    }
237
238 1
    public function foldLeft1(callable $callback): mixed
239
    {
240
        return $this->innerCollection->foldLeft1($callback);
241 2
    }
242
243 2
    public function foldRight(callable $callback, $initial): mixed
244
    {
245
        return $this->innerCollection->foldRight($callback, $initial);
246 1
    }
247
248 1
    public function foldRight1(callable $callback): mixed
249
    {
250
        return $this->innerCollection->foldRight1($callback);
251 1
    }
252
253 1
    public function forget(mixed ...$keys): static
254
    {
255
        return new static($this->innerCollection->forget(...$keys));
256
    }
257
258
    public function frequency(): static
259
    {
260
        return new static($this->innerCollection->frequency());
261
    }
262
263
    /**
264
     * @template UKey
265 1
     * @template U
266
     *
267 1
     * @param callable(mixed ...$parameters): iterable<UKey, U> $callable
268
     * @param iterable<int, mixed> $parameters
269
     *
270 1
     * @return static<UKey, U>
271
     */
272 1
    public static function fromCallable(callable $callable, iterable $parameters = []): static
273
    {
274
        return new static(Collection::fromCallable($callable, $parameters));
275 1
    }
276
277 1
    public static function fromFile(string $filepath): static
278
    {
279
        return new static(Collection::fromFile($filepath));
280
    }
281
282
    public static function fromGenerator(Generator $generator): static
283
    {
284
        return new static(Collection::fromGenerator($generator));
285
    }
286
287
    /**
288 1
     * @template UKey
289
     * @template U
290 1
     *
291
     * @param iterable<UKey, U> $iterable
292
     *
293
     * @return static<UKey, U>
294
     */
295
    public static function fromIterable(iterable $iterable): static
296
    {
297
        return new static(Collection::fromIterable($iterable));
298 1
    }
299
300 1
    /**
301
     * @param resource $resource
302
     *
303 1
     * @return static<int, string>
304
     */
305 1
    public static function fromResource($resource): static
306
    {
307
        return new static(Collection::fromResource($resource));
308 2
    }
309
310 2
    public static function fromString(string $string, string $delimiter = ''): static
311
    {
312
        return new static(Collection::fromString($string, $delimiter));
313
    }
314
315
    public function get(mixed $key, $default = null): mixed
316 200
    {
317
        return $this->innerCollection->get($key, $default);
318 200
    }
319
320
    /**
321 3
     * @return Traversable<TKey, T>
322
     */
323 3
    public function getIterator(): Traversable
324
    {
325
        yield from $this->innerCollection->getIterator();
326 2
    }
327
328 2
    public function group(): static
329
    {
330
        return new static($this->innerCollection->group());
331 8
    }
332
333 8
    public function groupBy(callable $callback): static
334
    {
335
        return new static($this->innerCollection->groupBy($callback));
336 3
    }
337
338 3
    public function has(callable ...$callbacks): bool
339
    {
340
        return $this->innerCollection->has(...$callbacks);
341 2
    }
342
343 2
    public function head($default = null): mixed
344
    {
345
        return $this->innerCollection->head($default);
346 3
    }
347
348 3
    public function ifThenElse(callable $condition, callable $then, ?callable $else = null): static
349
    {
350
        return new static($this->innerCollection->ifThenElse($condition, $then, $else));
351 2
    }
352
353 2
    public function implode(string $glue = ''): string
354
    {
355
        return $this->innerCollection->implode($glue);
356 2
    }
357
358 2
    public function init(): static
359
    {
360
        return new static($this->innerCollection->init());
361 2
    }
362
363 2
    public function inits(): static
364
    {
365
        return new static($this->innerCollection->inits());
366 3
    }
367
368 3
    public function intersect(mixed ...$values): static
369
    {
370
        return new static($this->innerCollection->intersect(...$values));
371 5
    }
372
373 5
    public function intersectKeys(mixed ...$keys): static
374
    {
375
        return new static($this->innerCollection->intersectKeys(...$keys));
376 7
    }
377
378 7
    public function intersperse(mixed $element, int $every = 1, int $startAt = 0): static
379
    {
380
        return new static($this->innerCollection->intersperse($element, $every, $startAt));
381 7
    }
382
383 7
    public function isEmpty(): bool
384
    {
385
        return $this->innerCollection->isEmpty();
386 3
    }
387
388 3
    public function isNotEmpty(): bool
389
    {
390
        return $this->innerCollection->isNotEmpty();
391 1
    }
392
393 1
    public function key(int $index = 0): mixed
394
    {
395
        return $this->innerCollection->key($index);
396 7
    }
397
398 7
    public function keys(): static
399
    {
400
        return new static($this->innerCollection->keys());
401 5
    }
402
403 5
    public function last($default = null): mixed
404
    {
405
        return $this->innerCollection->last($default);
406 1
    }
407
408 1
    public function limit(int $count = -1, int $offset = 0): static
409
    {
410
        return new static($this->innerCollection->limit($count, $offset));
411 2
    }
412
413 2
    public function lines(): static
414
    {
415
        return new static($this->innerCollection->lines());
416 2
    }
417
418 2
    public function map(callable $callback): static
419
    {
420
        return new static($this->innerCollection->map($callback));
421 3
    }
422
423 3
    public function mapN(callable ...$callbacks): static
424
    {
425
        return new static($this->innerCollection->mapN(...$callbacks));
426 1
    }
427
428 1
    public function match(callable $callback, ?callable $matcher = null): bool
429
    {
430
        return $this->innerCollection->match($callback, $matcher);
431 4
    }
432
433 4
    public function matching(Criteria $criteria): static
434
    {
435
        return new static($this->innerCollection->matching($criteria));
436 1
    }
437
438 1
    public function max($default = null): mixed
439
    {
440
        return $this->innerCollection->max($default);
441 4
    }
442
443 4
    public function merge(iterable ...$sources): static
444
    {
445
        return new static($this->innerCollection->merge(...$sources));
446 3
    }
447
448 3
    public function min($default = null): mixed
449
    {
450
        return $this->innerCollection->min($default);
451 2
    }
452
453 2
    public function normalize(): static
454
    {
455
        return new static($this->innerCollection->normalize());
456 4
    }
457
458 4
    public function nth(int $step, int $offset = 0): static
459
    {
460
        return new static($this->innerCollection->nth($step, $offset));
461 1
    }
462
463 1
    public function nullsy(): bool
464
    {
465
        return $this->innerCollection->nullsy();
466 1
    }
467
468 1
    public function pack(): static
469
    {
470
        return new static($this->innerCollection->pack());
471 2
    }
472
473 2
    public function pad(int $size, mixed $value): static
474
    {
475
        return new static($this->innerCollection->pad($size, $value));
476 1
    }
477
478 1
    public function pair(): static
479
    {
480
        return new static($this->innerCollection->pair());
481 1
    }
482
483 1
    public function partition(callable ...$callbacks): static
484
    {
485
        return new static($this->innerCollection->partition(...$callbacks));
486 1
    }
487
488 1
    public function permutate(): static
489
    {
490
        return new static($this->innerCollection->permutate());
491 6
    }
492
493 6
    public function pipe(callable ...$callbacks): static
494
    {
495
        return new static($this->innerCollection->pipe(...$callbacks));
496 1
    }
497
498 1
    public function pluck(mixed $pluck, mixed $default = null): static
499
    {
500
        return new static($this->innerCollection->pluck($pluck, $default));
501 2
    }
502
503 2
    public function prepend(mixed ...$items): static
504
    {
505
        return new static($this->innerCollection->prepend(...$items));
506 1
    }
507
508 1
    public function product(iterable ...$iterables): static
509
    {
510
        return new static($this->innerCollection->product(...$iterables));
511 1
    }
512
513 1
    public function random(int $size = 1, ?int $seed = null): static
514
    {
515
        return new static($this->innerCollection->random($size, $seed));
516 3
    }
517
518 3
    public static function range(float $start = 0.0, float $end = INF, float $step = 1.0): CollectionInterface
519
    {
520
        return new static(Collection::range($start, $end, $step));
521 1
    }
522
523 1
    public function reduce(callable $callback, mixed $initial = null): mixed
524
    {
525
        return $this->innerCollection->reduce($callback, $initial);
526 4
    }
527
528 4
    public function reduction(callable $callback, mixed $initial = null): static
529
    {
530
        return new static($this->innerCollection->reduction($callback, $initial));
531 2
    }
532
533 2
    public function reject(callable ...$callbacks): static
534
    {
535
        return new static($this->innerCollection->reject(...$callbacks));
536
    }
537
538
    public function reverse(): static
539
    {
540
        return new static($this->innerCollection->reverse());
541 23
    }
542
543 23
    public function rsample(float $probability): static
544
    {
545
        return new static($this->innerCollection->rsample($probability));
546 1
    }
547
548
    public function same(iterable $other, ?callable $comparatorCallback = null): bool
549
    {
550
        return $this->innerCollection->same($other, $comparatorCallback);
551
    }
552
553 1
    public function scale(
554
        float $lowerBound,
555
        float $upperBound,
556 2
        float $wantedLowerBound = 0.0,
557
        float $wantedUpperBound = 1.0,
558 2
        float $base = 0.0
559
    ): static {
560
        return new static($this->innerCollection->scale($lowerBound, $upperBound, $wantedLowerBound, $wantedUpperBound));
561 3
    }
562
563 3
    public function scanLeft(callable $callback, mixed $initial): static
564
    {
565
        return new static($this->innerCollection->scanLeft($callback, $initial));
566 2
    }
567
568 2
    public function scanLeft1(callable $callback): static
569
    {
570
        return new static($this->innerCollection->scanLeft1($callback));
571 2
    }
572
573 2
    public function scanRight(callable $callback, mixed $initial): static
574
    {
575
        return new static($this->innerCollection->scanRight($callback, $initial));
576 1
    }
577
578 1
    public function scanRight1(callable $callback): static
579
    {
580
        return new static($this->innerCollection->scanRight1($callback));
581 4
    }
582
583 4
    public function shuffle(?int $seed = null): static
584
    {
585
        return new static($this->innerCollection->shuffle($seed));
586 3
    }
587
588 3
    public function since(callable ...$callbacks): static
589
    {
590
        return new static($this->innerCollection->since(...$callbacks));
591 5
    }
592
593 5
    public function slice(int $offset, int $length = -1): static
594
    {
595
        return new static($this->innerCollection->slice($offset, $length));
596 1
    }
597
598 1
    public function sort(int $type = Operation\Sortable::BY_VALUES, ?callable $callback = null): static
599
    {
600
        return new static($this->innerCollection->sort($type, $callback));
601 3
    }
602
603 3
    public function span(callable ...$callbacks): static
604
    {
605
        return new static($this->innerCollection->span(...$callbacks));
606 1
    }
607
608 1
    public function split(int $type = Operation\Splitable::BEFORE, callable ...$callbacks): static
609
    {
610
        return new static($this->innerCollection->split($type, ...$callbacks));
611 1
    }
612
613 1
    public function squash(): static
614
    {
615
        return new static($this->innerCollection->squash());
616 1
    }
617
618 1
    public function strict(?callable $callback = null): static
619
    {
620
        return new static($this->innerCollection->strict($callback));
621 2
    }
622
623 2
    public function tail(): static
624
    {
625
        return new static($this->innerCollection->tail());
626 3
    }
627
628 3
    public function tails(): static
629
    {
630
        return new static($this->innerCollection->tails());
631 1
    }
632
633 1
    public function takeWhile(callable ...$callbacks): static
634
    {
635
        return new static($this->innerCollection->takeWhile(...$callbacks));
636 1
    }
637
638 1
    public static function times(int $number = 0, ?callable $callback = null): static
639
    {
640
        return new static(Collection::times($number, $callback));
641 4
    }
642
643 4
    public function transpose(): static
644
    {
645
        return new static($this->innerCollection->transpose());
646 1
    }
647
648 1
    public function truthy(): bool
649
    {
650
        return $this->innerCollection->truthy();
651 1
    }
652
653 1
    public static function unfold(callable $callback, iterable $parameters = []): static
654
    {
655
        return new static(Collection::unfold($callback, $parameters));
656 1
    }
657
658 1
    public function unlines(): string
659
    {
660
        return $this->innerCollection->unlines();
661 1
    }
662
663 1
    public function unpack(): static
664
    {
665
        return new static($this->innerCollection->unpack());
666 2
    }
667
668 2
    public function unpair(): static
669
    {
670
        return new static($this->innerCollection->unpair());
671 1
    }
672
673 1
    public function until(callable ...$callbacks): static
674
    {
675
        return new static($this->innerCollection->until(...$callbacks));
676 1
    }
677
678 1
    public function unwindow(): static
679
    {
680
        return new static($this->innerCollection->unwindow());
681 3
    }
682
683 3
    public function unwords(): string
684
    {
685
        return $this->innerCollection->unwords();
686 1
    }
687
688 1
    public function unwrap(): static
689
    {
690
        return new static($this->innerCollection->unwrap());
691 2
    }
692
693 2
    public function unzip(): static
694
    {
695
        return new static($this->innerCollection->unzip());
696 4
    }
697
698 4
    public function when(callable $predicate, callable $whenTrue, ?callable $whenFalse = null): static
699
    {
700
        return new static($this->innerCollection->when($predicate, $whenTrue, $whenFalse));
701 1
    }
702
703 1
    public function window(int $size): static
704
    {
705
        return new static($this->innerCollection->window($size));
706 2
    }
707
708 2
    public function words(): static
709
    {
710
        return new static($this->innerCollection->words());
711 2
    }
712
713 2
    public function wrap(): static
714
    {
715
        return new static($this->innerCollection->wrap());
716
    }
717
718
    public function zip(iterable ...$iterables): static
719
    {
720
        return new static($this->innerCollection->zip(...$iterables));
721
    }
722
}
723