Completed
Pull Request — master (#19)
by John
04:27
created

FieldParserRegistry::getParser()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 6
1
<?php
2
3
namespace Graze\CiffRenderer\Parser;
4
5
use Graze\CiffRenderer\Parser\FieldParser\FieldParserInterface;
6
use Graze\CiffRenderer\Exception\RuntimeException;
7
8
class FieldParserRegistry
9
{
10
    /**
11
     * @var FieldParserInterface[]
12
     */
13
    private $parsers;
14
15
    /**
16
     * @param FieldParserInterface $parser
17
     */
18
    public function addParser(FieldParserInterface $parser)
19
    {
20
        $this->parsers[$parser->getFieldName()] = $parser;
21
    }
22
23
    /**
24
     * @param string $name
25
     * @return FieldParserInterface
26
     * @throws RuntimeException
27
     */
28
    public function getParser($name)
29
    {
30
        if (!isset($this->parsers[$name])) {
31
            throw new RuntimeException(sprintf('Parser does not exist [%s]', $name));
32
        }
33
34
        return $this->parsers[$name];
35
    }
36
}
37