Passed
Branch master (6982d9)
by Ivan
02:35
created

RegexMatch   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 19
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A getValue() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Everlution\Navigation\Match\Voter;
6
7
use Everlution\Navigation\Match\MatchInterface;
8
9
/**
10
 * Class RegexMatch.
11
 *
12
 * @author Ivan Barlog <[email protected]>
13
 */
14
class RegexMatch implements MatchInterface
15
{
16
    /** @var string */
17
    private $value;
18
19
    public function __construct(string $pattern, string $modifiers = '')
20
    {
21
        $regex = sprintf('/%s/%s', str_replace('/', '\/', $pattern), $modifiers);
22
23
        if (false === preg_match($regex, '')) {
24
            throw new InvalidRegexPatternException($pattern);
25
        }
26
27
        $this->value = $regex;
28
    }
29
30
    public function getValue(): string
31
    {
32
        return $this->value;
33
    }
34
}
35