Passed
Push — 2.6 ( d150f9 )
by Colin
09:39
created

StrikethroughDelimiterProcessor::getCacheKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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