RegExpTag::process()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Jasny\PhpdocParser\Tag;
6
7
use Jasny\PhpdocParser\PhpdocException;
8
use Jasny\PhpdocParser\Tag\AbstractTag;
9
10
/**
11
 * Process using a regular expression
12
 */
13
class RegExpTag extends AbstractTag
14
{
15
    /**
16
     * @var string
17
     */
18
    protected $regexp;
19
20
    /**
21
     * Class constructor
22
     *
23
     * @param string         $name
24
     * @param string         $regexp
25
     */
26 5
    public function __construct(string $name, string $regexp)
27
    {
28 5
        parent::__construct($name);
29
30 5
        $this->regexp = $regexp;
31
    }
32
33
    /**
34
     * Get the regular expression
35
     *
36
     * @return string
37
     */
38 1
    public function getRegExp(): string
39
    {
40 1
        return $this->regexp;
41
    }
42
43
    /**
44
     * Process a notation
45
     *
46
     * @param array  $notations
47
     * @param string $value
48
     * @return array
49
     */
50 4
    public function process(array $notations, string $value): array
51
    {
52 4
        if (!preg_match($this->regexp, $value, $matches)) {
53 1
            throw new PhpdocException("Failed to parse '@{$this->name} $value': invalid syntax");
54
        }
55
56 3
        $notations[$this->name] = $matches;
57
58 3
        return $notations;
59
    }
60
}
61