Completed
Push — master ( 6c85d2...15e8d5 )
by Colin
04:57
created

ThematicBreakParser::parse()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 19
ccs 10
cts 10
cp 1
rs 9.4286
cc 3
eloc 10
nc 3
nop 2
crap 3
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 (http://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\ThematicBreak;
18
use League\CommonMark\ContextInterface;
19
use League\CommonMark\Cursor;
20
use League\CommonMark\Util\RegexHelper;
21
22
class ThematicBreakParser extends AbstractBlockParser
23
{
24
    /**
25
     * @param ContextInterface $context
26
     * @param Cursor           $cursor
27
     *
28
     * @return bool
29
     */
30 1674
    public function parse(ContextInterface $context, Cursor $cursor)
31
    {
32 1674
        if ($cursor->isIndented()) {
33 177
            return false;
34
        }
35
36 1620
        $match = RegexHelper::matchAt(RegexHelper::getInstance()->getThematicBreakRegex(), $cursor->getLine(), $cursor->getFirstNonSpacePosition());
37 1620
        if ($match === null) {
38 1587
            return false;
39
        }
40
41
        // Advance to the end of the string, consuming the entire line (of the thematic break)
42 78
        $cursor->advanceBy(mb_strlen($cursor->getRemainder()));
43
44 78
        $context->addBlock(new ThematicBreak());
45 78
        $context->setBlocksParsed(true);
46
47 78
        return true;
48
    }
49
}
50