Passed
Push — master ( 93a267...f5acbf )
by X
32s
created

TypeConvertParser::parse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * parse and then convert type for result
4
 */
5
namespace xKerman\Restricted;
6
7
/**
8
 * Parser that returns result as converted
9
 */
10
class TypeConvertParser implements ParserInterface
11
{
12
    /** @var ParserInterface $parser parser for given input */
13
    private $parser;
14
15
    /** @var ConverterInterface $converter converter for parser result */
16
    private $converter;
17
18
    /**
19
     * constructor
20
     *
21
     * @param ParserInterface    $parser    parser
22
     * @param ConverterInterface $converter converter for parser result
23
     */
24 12
    public function __construct(ParserInterface $parser, ConverterInterface $converter)
25
    {
26 12
        $this->parser = $parser;
27 12
        $this->converter = $converter;
28 12
    }
29
30
    /**
31
     * parse given `$source` and then convert type
32
     *
33
     * @param Source $source parser input
34
     * @return array
35
     * @throws UnserializeFailedException
36
     */
37 12
    public function parse(Source $source)
38
    {
39 12
        list($result, $source) = $this->parser->parse($source);
40 9
        return array($this->converter->convert($result), $source);
41
    }
42
}
43