Completed
Push — master ( 632183...ff01c5 )
by Ítalo
03:45
created

Set   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 13
c 1
b 0
f 1
lcom 1
cbo 4
dl 0
loc 94
ccs 0
cts 50
cp 0
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A at() 0 4 1
A get() 0 6 1
A containsKey() 0 4 1
A contains() 0 4 1
A set() 0 6 1
A removeKey() 0 4 1
A addAll() 0 10 4
A remove() 0 7 1
A getIterator() 0 4 1
A add() 0 6 1
1
<?php
2
3
namespace Collections;
4
5
use Collections\Iterator\SetIterator;
6
use Collections\Traits\GuardTrait;
7
use Collections\Traits\StrictKeyedIterableTrait;
8
9
class Set extends AbstractCollectionArray implements SetInterface
10
{
11
    use GuardTrait,
12
        StrictKeyedIterableTrait;
13
14
    public function at($k)
15
    {
16
        return $this[$k];
17
    }
18
19
    /**
20
     * @inheritDoc
21
     */
22
    public function get($key)
23
    {
24
        $this->validateKeyBounds($key);
25
26
        return $this->container[$key];
27
    }
28
29
    /**
30
     * @inheritDoc
31
     */
32
    public function containsKey($key)
33
    {
34
        return array_key_exists($key, $this->container);
35
    }
36
37
    /**
38
     * @inheritDoc
39
     */
40
    public function contains($item)
41
    {
42
        return in_array($item, $this->container, true);
43
    }
44
45
    /**
46
     * @inheritDoc
47
     */
48
    public function set($key, $value)
49
    {
50
        $this->container[$key] = $value;
51
52
        return $this;
53
    }
54
55
    /**
56
     * @inheritDoc
57
     */
58
    public function removeKey($key)
59
    {
60
        return $this->remove($key);
61
    }
62
63
    /**
64
     * @inheritDoc
65
     */
66
    public function addAll($items)
67
    {
68
        if (!is_array($items) && !$items instanceof \Traversable) {
69
            throw new \InvalidArgumentException('The items must be an array or Traversable');
70
        }
71
72
        foreach ($items as $value) {
73
            $this->add($value);
74
        }
75
    }
76
77
    public function remove($index)
78
    {
79
        $this->validateKeyBounds($index);
80
        unset($this->container[$index]);
81
82
        return $this;
83
    }
84
85
    /**
86
     * @inheritDoc
87
     */
88
    public function getIterator()
89
    {
90
        return new SetIterator();
91
    }
92
93
    /**
94
     * @inheritDoc
95
     */
96
    public function add($item)
97
    {
98
        $this->container[] = $item;
99
100
        return $this;
101
    }
102
}
103