getOpeningCharacter()   A
last analyzed

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 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 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]> 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\DelimiterProcessorInterface;
18
use League\CommonMark\Node\Inline\AbstractStringContainer;
19
20
final class StrikethroughDelimiterProcessor implements DelimiterProcessorInterface
21
{
22 171
    public function getOpeningCharacter(): string
23
    {
24 171
        return '~';
25
    }
26
27 171
    public function getClosingCharacter(): string
28
    {
29 171
        return '~';
30
    }
31
32 54
    public function getMinLength(): int
33
    {
34 54
        return 2;
35
    }
36
37 33
    public function getDelimiterUse(DelimiterInterface $opener, DelimiterInterface $closer): int
38
    {
39 33
        $min = \min($opener->getLength(), $closer->getLength());
40
41 33
        return $min >= 2 ? $min : 0;
42
    }
43
44 33
    public function process(AbstractStringContainer $opener, AbstractStringContainer $closer, int $delimiterUse): void
45
    {
46 33
        $strikethrough = new Strikethrough();
47
48 33
        $tmp = $opener->next();
49 33
        while ($tmp !== null && $tmp !== $closer) {
50 33
            $next = $tmp->next();
51 33
            $strikethrough->appendChild($tmp);
52 33
            $tmp = $next;
53
        }
54
55 33
        $opener->insertAfter($strikethrough);
56 33
    }
57
}
58