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

RegexpParser   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

2 Methods

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