DescriptionContinueParser   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 94.74%

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 47
ccs 18
cts 19
cp 0.9474
rs 10
c 0
b 0
f 0
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A canContain() 0 3 1
A getBlock() 0 3 1
A __construct() 0 4 1
A isContainer() 0 3 1
A tryContinue() 0 20 4
1
<?php
2
3
/*
4
 * This file is part of the league/commonmark package.
5
 *
6
 * (c) Colin O'Dell <[email protected]>
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
declare(strict_types=1);
13
14
namespace League\CommonMark\Extension\DescriptionList\Parser;
15
16
use League\CommonMark\Extension\DescriptionList\Node\Description;
17
use League\CommonMark\Node\Block\AbstractBlock;
18
use League\CommonMark\Parser\Block\AbstractBlockContinueParser;
19
use League\CommonMark\Parser\Block\BlockContinue;
20
use League\CommonMark\Parser\Block\BlockContinueParserInterface;
21
use League\CommonMark\Parser\Cursor;
22
23
final class DescriptionContinueParser extends AbstractBlockContinueParser
24
{
25
    private Description $block;
26
27
    private int $indentation;
28
29 22
    public function __construct(bool $tight, int $indentation)
30
    {
31 22
        $this->block       = new Description($tight);
32 22
        $this->indentation = $indentation;
33
    }
34
35 22
    public function getBlock(): Description
36
    {
37 22
        return $this->block;
38
    }
39
40 22
    public function tryContinue(Cursor $cursor, BlockContinueParserInterface $activeBlockParser): ?BlockContinue
41
    {
42 22
        if ($cursor->isBlank()) {
43 22
            if ($this->block->firstChild() === null) {
44
                // Blank line after empty item
45
                return BlockContinue::none();
46
            }
47
48 22
            $cursor->advanceToNextNonSpaceOrTab();
49
50 22
            return BlockContinue::at($cursor);
51
        }
52
53 22
        if ($cursor->getIndent() >= $this->indentation) {
54 10
            $cursor->advanceBy($this->indentation, true);
55
56 10
            return BlockContinue::at($cursor);
57
        }
58
59 22
        return BlockContinue::none();
60
    }
61
62 22
    public function isContainer(): bool
63
    {
64 22
        return true;
65
    }
66
67 22
    public function canContain(AbstractBlock $childBlock): bool
68
    {
69 22
        return true;
70
    }
71
}
72