Issues (172)

src/functions/iterable_flatten.php (2 issues)

Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Improved;
6
7
/**
8
 * Walk through all sub-iterables (array, Iterator or IteratorAggregate) and combine them.
9
 *
10
 * @param iterable $iterable
11
 * @param bool     $preserveKeys
12
 * @return \Generator
13
 */
14 12
function iterable_flatten(iterable $iterable, bool $preserveKeys = false): \Generator
0 ignored issues
show
Function Improved\iterable_flatten() has parameter $iterable with no value type specified in iterable type iterable.
Loading history...
Function Improved\iterable_flatten() return type has no value type specified in iterable type Generator.
Loading history...
15
{
16 11
    $counter = 0;
17
18 11
    foreach ($iterable as $topKey => $element) {
19 10
        if (!is_iterable($element)) {
20 10
            yield ($preserveKeys ? $topKey : $counter++) => $element;
21 10
            continue;
22
        }
23
24 10
        foreach ($element as $key => $item) {
25 10
            yield ($preserveKeys ? $key : $counter++) => $item;
26
        }
27
    }
28
}
29