IteratorEnvelope::rewind()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace MaxGoryunov\SavingIterator\Src;
4
5
use Iterator;
6
7
/**
8
 * Wraps objects which are not interators.
9
 * 
10
 * @template TKey
11
 * @template TValue
12
 * @implements Iterator<TKey, TValue>
13
 */
14
class IteratorEnvelope implements Iterator
15
{
16
17
    /**
18
     * Original object.
19
     * 
20
     * This is NOT necessarily an iterator
21
     * 
22
     * @var Iterator<TKey, TValue>|Indifferent<Iterator<TKey, TValue>>
23
     */
24
    private Iterator|Indifferent $origin;
25
26
    /**
27
     * Ctor.
28
     *
29
     * @param Iterator<TKey, TValue>|Indifferent<Iterator<TKey, TValue>> $iterable
30
     */
31
    public function __construct(Iterator|Indifferent $iterable)
32
    {
33
        $this->origin = $iterable;
0 ignored issues
show
Documentation Bug introduced by
It seems like $iterable can also be of type MaxGoryunov\SavingIterator\Src\Indifferent. However, the property $origin is declared as type Iterator. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
34
    }
35
36
    /**
37
     * {@inheritDoc}
38
     */
39
    public function current(): mixed
40
    {
41
        return $this->origin->current();
0 ignored issues
show
Bug introduced by
The method current() does not exist on MaxGoryunov\SavingIterator\Src\Indifferent. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

41
        return $this->origin->/** @scrutinizer ignore-call */ current();
Loading history...
42
    }
43
44
    /**
45
     * {@inheritDoc}
46
     */
47
    public function key(): mixed
48
    {
49
        return $this->origin->key();
0 ignored issues
show
Bug introduced by
The method key() does not exist on MaxGoryunov\SavingIterator\Src\Indifferent. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

49
        return $this->origin->/** @scrutinizer ignore-call */ key();
Loading history...
50
    }
51
52
    /**
53
     * {@inheritDoc}
54
     */
55
    public function valid(): bool
56
    {
57
        return $this->origin->valid();
0 ignored issues
show
Bug introduced by
The method valid() does not exist on MaxGoryunov\SavingIterator\Src\Indifferent. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

57
        return $this->origin->/** @scrutinizer ignore-call */ valid();
Loading history...
58
    }
59
60
    /**
61
     * {@inheritDoc}
62
     */
63
    public function next(): void
64
    {
65
        $this->origin->next();
0 ignored issues
show
Bug introduced by
The method next() does not exist on MaxGoryunov\SavingIterator\Src\Indifferent. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

65
        $this->origin->/** @scrutinizer ignore-call */ 
66
                       next();
Loading history...
66
    }
67
68
    /**
69
     * {@inheritDoc}
70
     */
71
    public function rewind(): void
72
    {
73
        $this->origin->rewind();
0 ignored issues
show
Bug introduced by
The method rewind() does not exist on MaxGoryunov\SavingIterator\Src\Indifferent. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

73
        $this->origin->/** @scrutinizer ignore-call */ 
74
                       rewind();
Loading history...
74
    }
75
}
76