Completed
Push — latest ( 609def...dcbb7e )
by Colin
14s queued 11s
created

InlineParserMatch   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 13
c 1
b 0
f 0
dl 0
loc 52
ccs 18
cts 18
cp 1
rs 10

6 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
A join() 0 8 2
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 2886
    private function __construct(string $regex)
22
    {
23 2886
        $this->regex = $regex;
24 2886
    }
25
26
    /**
27
     * @internal
28
     */
29 2913
    public function getRegex(): string
30
    {
31 2913
        return '/' . $this->regex . '/i';
32
    }
33
34
    /**
35
     * Match the given string (case-insensitive)
36
     */
37 2886
    public static function string(string $str): self
38
    {
39 2886
        return new self(\preg_quote($str, '/'));
40
    }
41
42
    /**
43
     * Match any of the given strings (case-insensitive)
44
     */
45 2886
    public static function oneOf(string ...$str): self
46
    {
47 1924
        return new self(\implode('|', \array_map(static function (string $str): string {
48 2886
            return \preg_quote($str, '/');
49 2886
        }, $str)));
50
    }
51
52
    /**
53
     * Match a partial regular expression without starting/ending delimiters, anchors, or flags
54
     */
55 2886
    public static function regex(string $regex): self
56
    {
57 2886
        return new self($regex);
58
    }
59
60 36
    public static function join(self ...$definitions): self
61
    {
62 36
        $regex = '';
63 36
        foreach ($definitions as $definition) {
64 36
            $regex .= '(' . $definition->regex . ')';
65
        }
66
67 36
        return new self($regex);
68
    }
69
}
70