Completed
Push — latest ( 76d169...995567 )
by Colin
22s queued 10s
created

InlineParserMatch   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 9
c 1
b 0
f 0
dl 0
loc 42
ccs 13
cts 13
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A regex() 0 3 1
A getRegex() 0 3 1
A oneOf() 0 5 1
A string() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the league/commonmark package.
7
 *
8
 * (c) Colin O'Dell <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace League\CommonMark\Parser\Inline;
15
16
final class InlineParserMatch
17
{
18
    /** @var string */
19
    private $regex;
20
21 2880
    private function __construct(string $regex)
22
    {
23 2880
        $this->regex = $regex;
24 2880
    }
25
26
    /**
27
     * @internal
28
     */
29 2904
    public function getRegex(): string
30
    {
31 2904
        return $this->regex;
32
    }
33
34
    /**
35
     * Match the given string (case-insensitive)
36
     */
37 2880
    public static function string(string $str): self
38
    {
39 2880
        return new self('/' . \preg_quote($str, '/') . '/i');
40
    }
41
42
    /**
43
     * Match any of the given strings (case-insensitive)
44
     */
45 2880
    public static function oneOf(string ...$str): self
46
    {
47 1920
        return new self('/' . \implode('|', \array_map(static function (string $str): string {
48 2880
            return \preg_quote($str, '/');
49 2880
        }, $str)) . '/i');
50
    }
51
52
    /**
53
     * Match a partial regular expression without starting/ending delimiters, anchors, or flags
54
     */
55 2880
    public static function regex(string $regex): self
56
    {
57 2880
        return new self('/' . $regex . '/i');
58
    }
59
}
60