FieldParserRegistry::getParser()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
ccs 3
cts 4
cp 0.75
crap 2.0625
rs 10
c 0
b 0
f 0
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 1
    public function addParser(FieldParserInterface $parser)
19
    {
20 1
        $this->parsers[$parser->getFieldName()] = $parser;
21 1
    }
22
23
    /**
24
     * @param string $name
25
     * @return FieldParserInterface
26
     * @throws RuntimeException
27
     */
28 1
    public function getParser($name)
29
    {
30 1
        if (!isset($this->parsers[$name])) {
31
            throw new RuntimeException(sprintf('Parser does not exist [%s]', $name));
32
        }
33
34 1
        return $this->parsers[$name];
35
    }
36
}
37