Eager::offsetExists()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\Parser\Containers;
4
5
use RuntimeException;
6
use Stratadox\Parser\Container;
7
use Stratadox\Parser\Parser;
8
9
/**
10
 * Eager container
11
 *
12
 * A basic typed list of regular parsers.
13
 */
14
final class Eager implements Container
15
{
16
    /** @var Parser[] */
17
    private array $parsers = [];
18
19
    public static function container(): Container
20
    {
21
        return new self();
22
    }
23
24
    public function offsetGet($name): Parser
25
    {
26
        if (!isset($this->parsers[$name])) {
27
            throw new RuntimeException("Missing the parser `$name`");
28
        }
29
        return $this->parsers[$name];
30
    }
31
32
    public function offsetSet($name, $parser): void
33
    {
34
        $this->parsers[$name] = $parser;
35
    }
36
37
    public function offsetExists($name): bool
38
    {
39
        return isset($this->parsers[$name]);
40
    }
41
42
    public function offsetUnset($name): void
43
    {
44
        unset($this->parsers[$name]);
45
    }
46
}
47