Completed
Push — refactor-04-parser-tests ( dc4950...bd4663 )
by John
06:06
created

FieldParserRegistry::getParser()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 3
cts 4
cp 0.75
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2.0625
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