Issues (172)

src/functions/iterable_chunk.php (2 issues)

Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Improved;
6
7
/**
8
 * Divide iterable into chunks of specified size.
9
 *
10
 * @param iterable $iterable
11
 * @param int      $size
12
 * @return \Generator
13
 */
14 13
function iterable_chunk(iterable $iterable, int $size): \Generator
0 ignored issues
show
Function Improved\iterable_chunk() has parameter $iterable with no value type specified in iterable type iterable.
Loading history...
Function Improved\iterable_chunk() return type has no value type specified in iterable type Generator.
Loading history...
15
{
16 12
    $generate = function (\Iterator $iterator, int $size): \Generator {
17 11
        for ($i = 0; $i < $size && $iterator->valid(); $i++) {
18 11
            yield $iterator->key() => $iterator->current();
19
20 11
            $iterator->next();
21
        }
22 12
    };
23
24 12
    $iterator = iterable_to_iterator($iterable);
25 12
    $iterator->rewind();
26
27 12
    while ($iterator->valid()) {
28 11
        yield $generate($iterator, $size);
29
    }
30
}
31