OptionMap::has()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cycle\Schema\Definition\Map;
6
7
use Cycle\Schema\Exception\OptionException;
8
9
/**
10
 * @implements \IteratorAggregate<string, mixed>
11
 */
12
final class OptionMap implements \IteratorAggregate
13
{
14
    private array $options = [];
15
16
    public function has(string $name): bool
17
    {
18 586
        return array_key_exists($name, $this->options);
19
    }
20 586
21
    /**
22
     * @throws OptionException
23
     */
24
    public function get(string $name): mixed
25
    {
26 24
        if (!$this->has($name)) {
27
            throw new OptionException("Undefined option `{$name}`");
28 24
        }
29 2
30
        return $this->options[$name];
31
    }
32 22
33
    public function set(string $name, mixed $value): self
34
    {
35 812
        $this->options[$name] = $value;
36
37 812
        return $this;
38
    }
39 812
40
    public function remove(string $name): self
41
    {
42 8
        unset($this->options[$name]);
43
44 8
        return $this;
45
    }
46 8
47
    public function getIterator(): \ArrayIterator
48
    {
49 1180
        return new \ArrayIterator($this->options);
50
    }
51
}
52