Passed
Push — master ( c5c96a...1eca3f )
by Smoren
03:24
created

IteratorFactory::makeIterator()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 7
c 1
b 0
f 1
nc 3
nop 1
dl 0
loc 9
ccs 6
cts 6
cp 1
crap 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Smoren\PartialIntersection\Util;
6
7
class IteratorFactory
8
{
9
    /**
10
     * @param iterable<mixed> $iterable
11
     *
12
     * @return \Iterator<mixed>|\IteratorIterator<mixed>|\ArrayIterator<mixed>
13
     */
14 97
    public static function makeIterator(iterable $iterable): \Iterator
15
    {
16
        switch (true) {
17 97
            case $iterable instanceof \Iterator:
18 46
                return $iterable;
19 51
            case $iterable instanceof \Traversable:
20 23
                return new \IteratorIterator($iterable);
21
            default:
22 28
                return new \ArrayIterator($iterable);
0 ignored issues
show
Bug introduced by
$iterable of type iterable is incompatible with the type array expected by parameter $array of ArrayIterator::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

22
                return new \ArrayIterator(/** @scrutinizer ignore-type */ $iterable);
Loading history...
23
        }
24
    }
25
}
26