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

TypeConvertParser   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A parse() 0 5 1
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