Passed
Push — master ( d4cc60...e821a3 )
by X
29s
created

StringParser::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
ccs 6
cts 6
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * parser for serialized string
4
 */
5
namespace xKerman\Restricted;
6
7
/**
8
 * Parser class for parse serialized PHP stirng
9
 */
10
class StringParser implements ParserInterface
11
{
12
    /** @var ParserInterface $parser internal parser */
13
    private $parser;
14
15
    /**
16
     * constructor
17
     */
18 37
    public function __construct()
19
    {
20 37
        $this->parser = new TypeConvertParser(
21 37
            new RegexpSubstringParser('/\Gs:[+]?[0-9]+:"/', 2, -2),
22 37
            new IntegerConverter()
23 37
        );
24 37
    }
25
26
    /**
27
     * parse give `$source` as PHP serialized string
28
     *
29
     * @param Source $source parser input
30
     * @return array parser result
31
     * @throws UnserializeFailedException
32
     */
33 18
    public function parse(Source $source)
34
    {
35 18
        list($length, $source) = $this->parser->parse($source);
36 9
        $result = $source->read($length);
37 9
        $source->consume('";');
38
39 8
        return array($result, $source);
40
    }
41
}
42