Passed
Push — master ( 0323c1...59b6fa )
by Pol
11:23
created

SortableIterableIterator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 34
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getIterator() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace loophp\collection\Iterator;
6
7
use ArrayIterator;
8
use IteratorAggregate;
9
10
/**
11
 * Class SortableIterableIterator.
12
 *
13
 * @implements IteratorAggregate<ArrayIterator>
14
 */
15
final class SortableIterableIterator implements IteratorAggregate
16
{
17
    /**
18
     * @var callable
19
     */
20
    private $callable;
21
22
    /**
23
     * @var \loophp\collection\Iterator\IterableIterator
24
     */
25
    private $iterator;
26
27
    /**
28
     * SortableIterator constructor.
29
     *
30
     * @param iterable<mixed> $iterable
31
     * @param callable $callable
32
     */
33
    public function __construct(iterable $iterable, callable $callable)
34
    {
35
        $this->callable = $callable;
36
        $this->iterator = new IterableIterator($iterable);
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function getIterator()
43
    {
44
        $arrayIterator = new ArrayIterator(iterator_to_array($this->iterator));
45
46
        $arrayIterator->uasort($this->callable);
0 ignored issues
show
Bug introduced by
$this->callable of type callable is incompatible with the type string expected by parameter $cmp_function of ArrayIterator::uasort(). ( Ignorable by Annotation )

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

46
        $arrayIterator->uasort(/** @scrutinizer ignore-type */ $this->callable);
Loading history...
47
48
        return $arrayIterator;
49
    }
50
}
51