Completed
Push — master ( 7ad8f7...a51edc )
by Alex
01:08 queued 53s
created

HashSetInternal::remove()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
6
namespace AlgoWeb\ODataMetadata\Structure;
7
8
use Iterator;
9
10
class HashSetInternal implements Iterator, \Countable
11
{
12
    private $wrappedDictionary = [];
13
14
    public function __construct(iterable $wrappedDictionary = null)
15
    {
16
        if (null !== $wrappedDictionary) {
17
            $wrappedDictionary = [];
18
            foreach ($wrappedDictionary as $item) {
19
                $this->wrappedDictionary[] = $item;
20
            }
21
        }
22
    }
23
24
    public function add($value): bool
25
    {
26
        if (in_array($value, $this->wrappedDictionary)) {
27
            return false;
28
        }
29
        $this->wrappedDictionary[] = $value;
30
        return true;
31
    }
32
33
    public function remove($value): void
34
    {
35
        $index = array_search($value, $this->wrappedDictionary);
36
        unset($this->wrappedDictionary[$index]);
37
    }
38
39
    public function tryGetValue($key, &$output)
0 ignored issues
show
Unused Code introduced by
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

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