Completed
Push — master ( 7289cd...72b6cd )
by Colin
12s
created

StrikethroughDelimiterProcessor::getDelimiterUse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 2
nc 2
nop 2
crap 2
1
<?php
2
3
/*
4
 * This file is part of the league/commonmark-ext-strikethrough package.
5
 *
6
 * (c) Colin O'Dell <[email protected]> and uAfrica.com (http://uafrica.com)
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace League\CommonMark\Ext\Strikethrough;
13
14
use League\CommonMark\Delimiter\Delimiter;
15
use League\CommonMark\Delimiter\Processor\DelimiterProcessorInterface;
16
use League\CommonMark\Inline\Element\AbstractStringContainer;
17
18
final class StrikethroughDelimiterProcessor implements DelimiterProcessorInterface
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23 51
    public function getOpeningCharacter(): string
24
    {
25 51
        return '~';
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 51
    public function getClosingCharacter(): string
32
    {
33 51
        return '~';
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 48
    public function getMinLength(): int
40
    {
41 48
        return 2;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 30
    public function getDelimiterUse(Delimiter $opener, Delimiter $closer): int
48
    {
49 30
        $min = \min($opener->getNumDelims(), $closer->getNumDelims());
50
51 30
        return $min >= 2 ? $min : 0;
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57 30
    public function process(AbstractStringContainer $opener, AbstractStringContainer $closer, int $delimiterUse)
58
    {
59 30
        $strikethrough = new Strikethrough();
60
61 30
        $tmp = $opener->next();
62 30
        while ($tmp !== null && $tmp !== $closer) {
63 30
            $next = $tmp->next();
64 30
            $strikethrough->appendChild($tmp);
65 30
            $tmp = $next;
66
        }
67
68 30
        $opener->insertAfter($strikethrough);
69 30
    }
70
}
71