OpenAddingIterator::valid()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace MaxGoryunov\SavingIterator\Src;
4
5
use ArrayAccess;
6
use Iterator;
7
8
/**
9
 * Adding iterator which stores values in a user provided iterator.
10
 * @template TKey
11
 * @template TValue
12
 * @implements AddingIterator<TKey, TValue>
13
 */
14
final class OpenAddingIterator implements AddingIterator
15
{
16
17
    /**
18
     * Ctor.
19
     * 
20
     * @phpstan-param Iterator<TKey, TValue>&ArrayAccess<TKey, TValue> $added
21
     * @param Iterator&ArrayAccess $added iterator with stored values.
22
     */
23
    public function __construct(
24
        /**
25
         * Iterator with stored values.
26
         * 
27
         * @phpstan-var Iterator<TKey, TValue>&ArrayAccess<TKey, TValue>
28
         * @var Iterator&ArrayAccess
29
         */
30
        private Iterator|ArrayAccess $added
31
    ) {
32
    }
33
34
    /**
35
     * {@inheritDoc}
36
     */
37
    public function from(Iterator $source): AddingIterator
38
    {
39
        $updated                   = clone $this->added;
40
        $updated[$source->key()] ??= $source->current();
41
        return new self($updated);
42
    }
43
44
    /**
45
     * {@inheritDoc}
46
     */
47
    public function current(): mixed
48
    {
49
        return $this->added->current();
0 ignored issues
show
Bug introduced by
The method current() does not exist on ArrayAccess. It seems like you code against a sub-type of said class. However, the method does not exist in http\Params or Judy or pq\Types or Threaded or HttpQueryString or WeakMap or Thread or SolrObject or http\QueryString or Symfony\Component\EventDispatcher\GenericEvent or Worker or ArrayObject or Symfony\Component\OptionsResolver\Options or Volatile or Thread or Worker or Worker or Symfony\Component\OptionsResolver\OptionsResolver. Are you sure you never get one of those? ( 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->added->/** @scrutinizer ignore-call */ current();
Loading history...
50
    }
51
52
    /**
53
     * {@inheritDoc}
54
     */
55
    public function key(): mixed
56
    {
57
        return $this->added->key();
0 ignored issues
show
Bug introduced by
The method key() does not exist on ArrayAccess. It seems like you code against a sub-type of said class. However, the method does not exist in http\Params or Judy or pq\Types or Threaded or HttpQueryString or WeakMap or Thread or SolrObject or http\QueryString or Symfony\Component\EventDispatcher\GenericEvent or Worker or ArrayObject or Symfony\Component\OptionsResolver\Options or Volatile or Thread or Worker or Worker or Symfony\Component\OptionsResolver\OptionsResolver. Are you sure you never get one of those? ( 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->added->/** @scrutinizer ignore-call */ key();
Loading history...
58
    }
59
60
    /**
61
     * {@inheritDoc}
62
     */
63
    public function next(): void
64
    {
65
        $this->added->next();
0 ignored issues
show
Bug introduced by
The method next() does not exist on ArrayAccess. It seems like you code against a sub-type of said class. However, the method does not exist in http\Params or pq\Types or Threaded or HttpQueryString or WeakMap or Thread or SolrObject or http\QueryString or Symfony\Component\EventDispatcher\GenericEvent or Worker or ArrayObject or Symfony\Component\OptionsResolver\Options or Volatile or Thread or Worker or Worker or Symfony\Component\OptionsResolver\OptionsResolver. Are you sure you never get one of those? ( 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->added->/** @scrutinizer ignore-call */ 
66
                      next();
Loading history...
66
    }
67
68
    /**
69
     * {@inheritDoc}
70
     */
71
    public function valid(): bool
72
    {
73
        return $this->added->valid();
0 ignored issues
show
Bug introduced by
The method valid() does not exist on ArrayAccess. It seems like you code against a sub-type of said class. However, the method does not exist in http\Params or Judy or pq\Types or Threaded or HttpQueryString or WeakMap or Thread or SolrObject or http\QueryString or Symfony\Component\EventDispatcher\GenericEvent or Worker or ArrayObject or Symfony\Component\OptionsResolver\Options or Volatile or Thread or Worker or Worker or Symfony\Component\OptionsResolver\OptionsResolver. Are you sure you never get one of those? ( Ignorable by Annotation )

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

73
        return $this->added->/** @scrutinizer ignore-call */ valid();
Loading history...
74
    }
75
76
    /**
77
     * {@inheritDoc}
78
     */
79
    public function rewind(): void
80
    {
81
        $this->added->rewind();
0 ignored issues
show
Bug introduced by
The method rewind() does not exist on ArrayAccess. It seems like you code against a sub-type of said class. However, the method does not exist in http\Params or Judy or pq\Types or Threaded or HttpQueryString or WeakMap or Thread or SolrObject or http\QueryString or Symfony\Component\EventDispatcher\GenericEvent or Worker or ArrayObject or Symfony\Component\OptionsResolver\Options or Volatile or Thread or Worker or Worker or Symfony\Component\OptionsResolver\OptionsResolver. Are you sure you never get one of those? ( Ignorable by Annotation )

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

81
        $this->added->/** @scrutinizer ignore-call */ 
82
                      rewind();
Loading history...
82
    }
83
}
84