FieldParserRegistry::addParser()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
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