Passed
Push — main ( fdd5ef...b703d3 )
by Colin
04:18 queued 01:32
created

MarkDelimiterProcessor::getCacheKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
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\Extension\Highlight;
15
16
use League\CommonMark\Delimiter\DelimiterInterface;
17
use League\CommonMark\Delimiter\Processor\DelimiterProcessorInterface;
18
use League\CommonMark\Node\Inline\AbstractStringContainer;
19
20
class MarkDelimiterProcessor implements DelimiterProcessorInterface
21
{
22 60
    public function getOpeningCharacter(): string
23
    {
24 60
        return '=';
25
    }
26
27 60
    public function getClosingCharacter(): string
28
    {
29 60
        return '=';
30
    }
31
32 58
    public function getMinLength(): int
33
    {
34 58
        return 2;
35
    }
36
37 44
    public function getDelimiterUse(DelimiterInterface $opener, DelimiterInterface $closer): int
38
    {
39 44
        if ($opener->getLength() > 2 && $closer->getLength() > 2) {
40 2
            return 0;
41
        }
42
43 42
        if ($opener->getLength() !== $closer->getLength()) {
44 14
            return 0;
45
        }
46
47
        // $opener and $closer are the same length so we just return one of them
48 38
        return $opener->getLength();
49
    }
50
51 38
    public function process(AbstractStringContainer $opener, AbstractStringContainer $closer, int $delimiterUse): void
52
    {
53 38
        $mark = new Mark(\str_repeat('=', $delimiterUse));
54
55 38
        $next = $opener->next();
56 38
        while ($next !== null && $next !== $closer) {
57 38
            $tmp = $next->next();
58 38
            $mark->appendChild($next);
59 38
            $next = $tmp;
60
        }
61
62 38
        $opener->insertAfter($mark);
63
    }
64
65
    public function getCacheKey(DelimiterInterface $closer): string
66
    {
67
        return '=' . $closer->getLength();
68
    }
69
}
70