Completed
Push — master ( fa5c7f...97ce41 )
by X
03:22
created

LengthParser::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
/**
3
 * provide parser for length
4
 */
5
namespace xKerman\Restricted;
6
7
/**
8
 * Parser for length, non-negative integer
9
 */
10
class LengthParser implements ParserInterface
11
{
12
    /** @var ParserInterface $parser internal parser for length */
13
    private $parser;
14
15
    /**
16
     * constructor
17
     */
18 13
    public function __construct()
19
    {
20 13
        $this->parser = new NumberLiteralParser();
21 13
    }
22
23
    /**
24
     * parse given `$source` as length, non-negative integer
25
     *
26
     * @param Source $source parser input
27
     * @return array
28
     * @throws UnserializeFailedException
29
     */
30 13
    public function parse(Source $source)
31
    {
32 13
        list($length, $source) = $this->parser->parse($source);
33 12
        if ($length < 0) {
34 1
            return $source->triggerError();
35
        }
36 11
        return array($length, $source);
37
    }
38
}
39