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

LengthParser   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 29
ccs 8
cts 8
cp 1
rs 10
wmc 3
lcom 1
cbo 2

2 Methods

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