Completed
Push — latest ( 6c0640...3af091 )
by Colin
16s queued 11s
created

HtmlBlockStartParser   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 13
dl 0
loc 24
ccs 13
cts 13
cp 1
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B tryStart() 0 22 7
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]>
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\CommonMark\Parser\Block;
15
16
use League\CommonMark\Node\Block\Paragraph;
17
use League\CommonMark\Parser\Block\BlockStart;
18
use League\CommonMark\Parser\Block\BlockStartParserInterface;
19
use League\CommonMark\Parser\Cursor;
20
use League\CommonMark\Parser\MarkdownParserStateInterface;
21
use League\CommonMark\Util\RegexHelper;
22
23
final class HtmlBlockStartParser implements BlockStartParserInterface
24
{
25 1953
    public function tryStart(Cursor $cursor, MarkdownParserStateInterface $parserState): ?BlockStart
26
    {
27 1953
        if ($cursor->isIndented() || $cursor->getNextNonSpaceCharacter() !== '<') {
28 1707
            return BlockStart::none();
29
        }
30
31 303
        $tmpCursor = clone $cursor;
32 303
        $tmpCursor->advanceToNextNonSpaceOrTab();
33 303
        $line = $tmpCursor->getRemainder();
34
35 303
        for ($blockType = 1; $blockType <= 7; $blockType++) {
36 303
            $match = RegexHelper::matchAt(
37 303
                RegexHelper::getHtmlBlockOpenRegex($blockType),
38 202
                $line
39
            );
40
41 303
            if ($match !== null && ($blockType < 7 || ! ($parserState->getLastMatchedBlockParser()->getBlock() instanceof Paragraph))) {
42 171
                return BlockStart::of(new HtmlBlockParser($blockType))->at($cursor);
43
            }
44
        }
45
46 144
        return BlockStart::none();
47
    }
48
}
49