Completed
Pull Request — master (#16)
by X
03:10
created

LengthParser::parse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

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