Completed
Push — master ( 83739a...a13ee4 )
by Colin
14s queued 11s
created

StrikethroughDelimiterProcessor   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 4
dl 0
loc 53
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getOpeningCharacter() 0 4 1
A getClosingCharacter() 0 4 1
A getMinLength() 0 4 1
A getDelimiterUse() 0 6 2
A process() 0 13 3
1
<?php
2
3
/*
4
 * This file is part of the league/commonmark 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\Extension\Strikethrough;
13
14
use League\CommonMark\Delimiter\DelimiterInterface;
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 123
    public function getOpeningCharacter(): string
24
    {
25 123
        return '~';
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 123
    public function getClosingCharacter(): string
32
    {
33 123
        return '~';
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 54
    public function getMinLength(): int
40
    {
41 54
        return 2;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 33
    public function getDelimiterUse(DelimiterInterface $opener, DelimiterInterface $closer): int
48
    {
49 33
        $min = \min($opener->getLength(), $closer->getLength());
50
51 33
        return $min >= 2 ? $min : 0;
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57 33
    public function process(AbstractStringContainer $opener, AbstractStringContainer $closer, int $delimiterUse)
58
    {
59 33
        $strikethrough = new Strikethrough();
60
61 33
        $tmp = $opener->next();
62 33
        while ($tmp !== null && $tmp !== $closer) {
63 33
            $next = $tmp->next();
64 33
            $strikethrough->appendChild($tmp);
65 33
            $tmp = $next;
66
        }
67
68 33
        $opener->insertAfter($strikethrough);
69 33
    }
70
}
71