Completed
Push — refactor-parsing ( adbb6b...fbe6de )
by Colin
08:21 queued 07:01
created

HtmlBlockStartParser::tryStart()   B

Complexity

Conditions 7
Paths 4

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 7

Importance

Changes 0
Metric Value
dl 0
loc 23
ccs 13
cts 13
cp 1
rs 8.6186
c 0
b 0
f 0
cc 7
nc 4
nop 2
crap 7
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
namespace League\CommonMark\Extension\CommonMark\Parser\Block;
13
14
use League\CommonMark\Node\Block\Paragraph;
15
use League\CommonMark\Parser\Block\BlockStart;
16
use League\CommonMark\Parser\Block\BlockStartParserInterface;
17
use League\CommonMark\Parser\Cursor;
18
use League\CommonMark\Parser\MarkdownParserStateInterface;
19
use League\CommonMark\Util\RegexHelper;
20
21
final class HtmlBlockStartParser implements BlockStartParserInterface
22
{
23 1812
    public function tryStart(Cursor $cursor, MarkdownParserStateInterface $parserState): ?BlockStart
24
    {
25 1812
        if ($cursor->isIndented() || $cursor->getNextNonSpaceCharacter() !== '<') {
26 1569
            return BlockStart::none();
27
        }
28
29 300
        $tmpCursor = clone $cursor;
30 300
        $tmpCursor->advanceToNextNonSpaceOrTab();
31 300
        $line = $tmpCursor->getRemainder();
32
33 300
        for ($blockType = 1; $blockType <= 7; $blockType++) {
34 300
            $match = RegexHelper::matchAt(
35 300
                RegexHelper::getHtmlBlockOpenRegex($blockType),
36 100
                $line
37
            );
38
39 300
            if ($match !== null && ($blockType < 7 || !($parserState->getLastMatchedBlockParser()->getBlock() instanceof Paragraph))) {
40 168
                return BlockStart::of(new HtmlBlockParser($blockType))->at($cursor);
41
            }
42
        }
43
44 144
        return BlockStart::none();
45
    }
46
}
47