HtmlBlockParser   A
last analyzed

Coupling/Cohesion

Components 0
Dependencies 5

Complexity

Total Complexity 7

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 5
dl 0
loc 43
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C parse() 0 34 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
 * Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
9
 *  - (c) John MacFarlane
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 */
14
15
namespace League\CommonMark\Block\Parser;
16
17
use League\CommonMark\Block\Element\HtmlBlock;
18
use League\CommonMark\Block\Element\Paragraph;
19
use League\CommonMark\ContextInterface;
20
use League\CommonMark\Cursor;
21
use League\CommonMark\Util\RegexHelper;
22
23
class HtmlBlockParser extends AbstractBlockParser
24
{
25
    /**
26
     * @param ContextInterface $context
27
     * @param Cursor           $cursor
28
     *
29
     * @return bool
30
     */
31 1815
    public function parse(ContextInterface $context, Cursor $cursor)
32
    {
33 1815
        if ($cursor->isIndented()) {
34 180
            return false;
35
        }
36
37 1758
        if ($cursor->getNextNonSpaceCharacter() !== '<') {
38 1599
            return false;
39
        }
40
41 279
        $savedState = $cursor->saveState();
42
43 279
        $cursor->advanceToNextNonSpaceOrTab();
44 279
        $line = $cursor->getRemainder();
45
46 279
        for ($blockType = 1; $blockType <= 7; $blockType++) {
47 279
            $match = RegexHelper::matchAt(
48 279
                RegexHelper::getHtmlBlockOpenRegex($blockType),
49
                $line
50 279
            );
51
52 279
            if ($match !== null && ($blockType < 7 || !($context->getContainer() instanceof Paragraph))) {
53 159
                $cursor->restoreState($savedState);
54 159
                $context->addBlock(new HtmlBlock($blockType));
55 159
                $context->setBlocksParsed(true);
56
57 159
                return true;
58
            }
59 261
        }
60
61 129
        $cursor->restoreState($savedState);
62
63 129
        return false;
64
    }
65
}
66