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

InlineParserMatch::join()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 10
cc 2
nc 2
nop 1
crap 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