Pad   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 11
c 0
b 0
f 0
dl 0
loc 34
ccs 11
cts 11
cp 1
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 29 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace loophp\collection\Operation;
6
7
use Closure;
8
use Generator;
9
10
/**
11
 * @immutable
12
 *
13
 * @template TKey
14
 * @template T
15
 */
16
final class Pad extends AbstractOperation
17
{
18
    /**
19
     * @return Closure(int): Closure(T): Closure(iterable<TKey, T>): Generator<int|TKey, T>
20
     */
21 2
    public function __invoke(): Closure
22
    {
23 2
        return
24
            /**
25
             * @return Closure(T): Closure(iterable<TKey, T>): Generator<int|TKey, T>
26
             */
27 2
            static fn (int $size): Closure =>
28
                /**
29
                 * @param T $padValue
30
                 *
31
                 * @return Closure(iterable<TKey, T>): Generator<int|TKey, T>
32
                 */
33 2
                static fn (mixed $padValue): Closure =>
34
                    /**
35
                     * @param iterable<TKey, T> $iterable
36
                     *
37
                     * @return Generator<int|TKey, T>
38
                     */
39 2
                    static function (iterable $iterable) use ($size, $padValue): Generator {
40 2
                        $y = 0;
41
42 2
                        foreach ($iterable as $key => $value) {
43 2
                            ++$y;
44
45 2
                            yield $key => $value;
46
                        }
47
48 2
                        while ($y++ < $size) {
49 2
                            yield $padValue;
50
                        }
51 2
                    };
52
    }
53
}
54