Passed
Push — master ( ad038c...02f8e8 )
by Anton
01:54
created

OptionMap   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 56
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A has() 0 3 1
A getIterator() 0 3 1
A set() 0 5 1
A remove() 0 5 1
A get() 0 7 2
1
<?php
2
declare(strict_types=1);
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
namespace Cycle\Schema\Definition\Map;
11
12
use Cycle\Schema\Exception\OptionException;
13
14
final class OptionMap
15
{
16
    /** @var array */
17
    private $options = [];
18
19
    /**
20
     * @param string $name
21
     * @return bool
22
     */
23
    public function has(string $name): bool
24
    {
25
        return isset($this->options[$name]);
26
    }
27
28
    /**
29
     * @param string $name
30
     * @return mixed
31
     */
32
    public function get(string $name)
33
    {
34
        if (!$this->has($name)) {
35
            throw new OptionException("Undefined option `{$name}`");
36
        }
37
38
        return $this->options[$name];
39
    }
40
41
    /**
42
     * @param string $name
43
     * @param mixed  $value
44
     * @return OptionMap
45
     */
46
    public function set(string $name, $value): self
47
    {
48
        $this->options[$name] = $value;
49
50
        return $this;
51
    }
52
53
    /**
54
     * @param string $name
55
     * @return OptionMap
56
     */
57
    public function remove(string $name): self
58
    {
59
        unset($this->options[$name]);
60
61
        return $this;
62
    }
63
64
    /**
65
     * @return \Traversable
66
     */
67
    public function getIterator()
68
    {
69
        return new \ArrayIterator($this->options);
70
    }
71
}