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

IteratorFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 8
c 1
b 0
f 1
dl 0
loc 16
ccs 6
cts 6
cp 1
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A makeIterator() 0 9 3
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