Completed
Push — master ( b4ff9c...fbe6de )
by Colin
01:00
created

ThematicBreakStartParser::tryStart()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 8
cts 8
cp 1
rs 9.7333
c 0
b 0
f 0
cc 3
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
 * 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\Parser\Block\BlockStart;
15
use League\CommonMark\Parser\Block\BlockStartParserInterface;
16
use League\CommonMark\Parser\Cursor;
17
use League\CommonMark\Parser\MarkdownParserStateInterface;
18
use League\CommonMark\Util\RegexHelper;
19
20
final class ThematicBreakStartParser implements BlockStartParserInterface
21
{
22 1692
    public function tryStart(Cursor $cursor, MarkdownParserStateInterface $parserState): ?BlockStart
23
    {
24 1692
        if ($cursor->isIndented()) {
25 183
            return BlockStart::none();
26
        }
27
28 1584
        $match = RegexHelper::matchAt(RegexHelper::REGEX_THEMATIC_BREAK, $cursor->getLine(), $cursor->getNextNonSpacePosition());
29 1584
        if ($match === null) {
30 1521
            return BlockStart::none();
31
        }
32
33
        // Advance to the end of the string, consuming the entire line (of the thematic break)
34 87
        $cursor->advanceToEnd();
35
36 87
        return BlockStart::of(new ThematicBreakParser())->at($cursor);
37
    }
38
}
39