Passed
Push — master ( bde555...a1caf7 )
by X
31s
created

RegexpParser::parse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 9.4285
1
<?php
2
/**
3
 * parser for regexp match and then substring
4
 */
5
namespace xKerman\Restricted;
6
7
/**
8
 * Parser that first process regexp match, and then substring the result
9
 */
10
class RegexpParser implements ParserInterface
11
{
12
    /** @var string $regexp regexp for matching */
13
    private $regexp;
14
15
    /**
16
     * constructor
17
     *
18
     * @param string $regexp regexp for matching
19
     */
20 40
    public function __construct($regexp)
21
    {
22 40
        $this->regexp = $regexp;
23 40
    }
24
25
    /**
26
     * parse given `$source` and return substring result
27
     *
28
     * @param Source $source parser input
29
     * @return array
30
     * @throws UnserializeFailedException
31
     */
32 22
    public function parse(Source $source)
33
    {
34 22
        $result = $source->match($this->regexp);
35 18
        return array($result, $source);
36
    }
37
}
38