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

StringParser   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 32
ccs 11
cts 11
cp 1
rs 10
c 1
b 0
f 0
wmc 2
lcom 1
cbo 4

2 Methods

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