Issues (126)

src/Structure/HashSetInternal.php (1 issue)

Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AlgoWeb\ODataMetadata\Structure;
6
7
use Iterator;
8
9
class HashSetInternal implements Iterator, \Countable
10
{
11
    private $wrappedDictionary = [];
12
13
    public function __construct(iterable $wrappedDictionary = null)
14
    {
15
        if (null !== $wrappedDictionary) {
16
            $wrappedDictionary = [];
17
            foreach ($wrappedDictionary as $item) {
18
                $this->wrappedDictionary[] = $item;
19
            }
20
        }
21
    }
22
23
    public function add($value): bool
24
    {
25
        if (in_array($value, $this->wrappedDictionary)) {
26
            return false;
27
        }
28
        $this->wrappedDictionary[] = $value;
29
        return true;
30
    }
31
32
    public function remove($value): void
33
    {
34
        $index = array_search($value, $this->wrappedDictionary);
35
        unset($this->wrappedDictionary[$index]);
36
    }
37
38
    public function tryGetValue($key, &$output)
0 ignored issues
show
The parameter $output is not used and could be removed. ( Ignorable by Annotation )

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

38
    public function tryGetValue($key, /** @scrutinizer ignore-unused */ &$output)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
39
    {
40
        if (isset($this->wrappedDictionary[$key])) {
41
            $output = &$this->wrappedDictionary[$key];
42
            return true;
43
        }
44
        return false;
45
    }
46
47
    public function contains($item): bool
48
    {
49
        return in_array($item, $this->wrappedDictionary);
50
    }
51
52
    /**
53
     * Return the current element.
54
     * @see https://php.net/manual/en/iterator.current.php
55
     * @return mixed can return any type
56
     * @since 5.0.0
57
     */
58
    public function current()
59
    {
60
        return current($this->wrappedDictionary);
61
    }
62
63
    /**
64
     * Move forward to next element.
65
     * @see https://php.net/manual/en/iterator.next.php
66
     * @return void any returned value is ignored
67
     * @since 5.0.0
68
     */
69
    public function next()
70
    {
71
        next($this->wrappedDictionary);
72
    }
73
74
    /**
75
     * Return the key of the current element.
76
     * @see https://php.net/manual/en/iterator.key.php
77
     * @return mixed scalar on success, or null on failure
78
     * @since 5.0.0
79
     */
80
    public function key()
81
    {
82
        return key($this->wrappedDictionary);
83
    }
84
85
    /**
86
     * Checks if current position is valid.
87
     * @see https://php.net/manual/en/iterator.valid.php
88
     * @return bool The return value will be casted to boolean and then evaluated.
89
     *              Returns true on success or false on failure.
90
     * @since 5.0.0
91
     */
92
    public function valid()
93
    {
94
        return key($this->wrappedDictionary) !== null;
95
    }
96
97
    /**
98
     * Rewind the Iterator to the first element.
99
     * @see https://php.net/manual/en/iterator.rewind.php
100
     * @return void any returned value is ignored
101
     * @since 5.0.0
102
     */
103
    public function rewind()
104
    {
105
        reset($this->wrappedDictionary);
106
    }
107
108
    /**
109
     * {@inheritdoc}
110
     */
111
    public function count()
112
    {
113
        return count($this->wrappedDictionary);
114
    }
115
}
116