Map   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 8
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 50
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A set() 0 10 3
A get() 0 8 2
A has() 0 4 1
A getKeys() 0 4 1
A getIterator() 0 4 1
1
<?php
2
3
namespace DCP\Mapper\Collections\Maps;
4
5
use DCP\Mapper\Exception\InvalidArgumentException;
6
use DCP\Mapper\Exception\OutOfBoundsException;
7
8
class Map implements MapInterface
9
{
10
    /**
11
     * @var array
12
     */
13
    private $map = [];
14
15
    /**
16
     * {@inheritdoc}
17
     * @throws InvalidArgumentException
18
     */
19
    public function set($key, $value)
20
    {
21
        if (!is_string($key) && !is_int($key)) {
22
            throw new InvalidArgumentException('$key must be a string or integer');
23
        }
24
25
        $this->map[$key] = $value;
26
27
        return $this;
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     * @throws OutOfBoundsException
33
     */
34
    public function get($key)
35
    {
36
        if (!array_key_exists($key, $this->map)) {
37
            throw new OutOfBoundsException(sprintf('The key "%s" does not exist', $key));
38
        }
39
40
        return $this->map[$key];
41
    }
42
43
    public function has($key)
44
    {
45
        return array_key_exists($key, $this->map);
46
    }
47
48
    public function getKeys()
49
    {
50
        return array_keys($this->map);
51
    }
52
53
    public function getIterator()
54
    {
55
        return new \ArrayIterator($this->map);
56
    }
57
}
58