Test Failed
Push — feature/84 ( 20c8e6...87da0b )
by Max
03:06 queued 12s
created

IteratorTransfer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
cc 1
eloc 0
c 2
b 0
f 2
nc 1
nop 1
dl 0
loc 9
rs 10
1
<?php
2
3
namespace MaxGoryunov\SavingIterator\Fakes;
4
5
use Iterator;
6
use MaxGoryunov\SavingIterator\Src\AddingIterator;
7
8
/**
9
 * Performs transfer of values from iterator to adding iterator.
10
 * @template TKey
11
 * @template TValue
12
 */
13
final class IteratorTransfer
14
{
15
16
    /**
17
     * Ctor.
18
     * 
19
     * @phpstan-param Iterator<TKey, TValue> $origin
20
     * @param Iterator $origin original iterator.
21
     */
22
    public function __construct(
23
        /**
24
         * Original iterator.
25
         *
26
         * @phpstan-var Iterator<TKey, TValue>
27
         * @var Iterator
28
         */
29
        private Iterator $origin
30
    ) {
31
    }
32
33
    /**
34
     * Transfers all values from origin to target.
35
     *
36
     * @phpstan-param AddingIterator<TKey, TValue> $target
37
     * @param AddingIterator $target
38
     * @phpstan-return AddingIterator<TKey, TValue>
39
     * @return AddingIterator
40
     */
41
    public function toTarget(AddingIterator $target): AddingIterator
42
    {
43
        $this->origin->rewind();
44
        while ($this->origin->valid()) {
45
            $target = $target->from($this->origin);
46
            $this->origin->next();
47
        }
48
        return $target;
49
    }
50
}
51