MappedLinkedListIterator::key()   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
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Smoren\Containers\Structs;
4
5
use Iterator;
6
7
/**
8
 * Class MappedLinkedListIterator
9
 */
10
class MappedLinkedListIterator implements Iterator
11
{
12
    /**
13
     * @var MappedLinkedList iterator owner
14
     */
15
    protected MappedLinkedList $owner;
16
    /**
17
     * @var LinkedListItem|null current position
18
     */
19
    protected ?LinkedListItem $position = null;
20
21
    /**
22
     * LinkedListIterator constructor.
23
     * @param MappedLinkedList $owner iterator owner
24
     */
25
    public function __construct(MappedLinkedList $owner)
26
    {
27
        $this->owner = $owner;
28
    }
29
30
    /**
31
     * @inheritDoc
32
     */
33
    public function current()
34
    {
35
        return $this->position->getData();
0 ignored issues
show
Bug introduced by
The method getData() does not exist on null. ( Ignorable by Annotation )

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

35
        return $this->position->/** @scrutinizer ignore-call */ getData();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
36
    }
37
38
    /**
39
     * @inheritDoc
40
     */
41
    public function next(): void
42
    {
43
        $this->position = $this->position->getNext();
44
    }
45
46
    /**
47
     * @inheritDoc
48
     */
49
    public function key(): string
50
    {
51
        return $this->position->getExtra();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->position->getExtra() could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
52
    }
53
54
    /**
55
     * @inheritDoc
56
     */
57
    public function valid(): bool
58
    {
59
        return $this->position !== null;
60
    }
61
62
    /**
63
     * @inheritDoc
64
     */
65
    public function rewind(): void
66
    {
67
        $this->position = $this->owner->getList()->getFirst();
68
    }
69
}
70