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

FencedCodeStartParser::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\Parser\Block\BlockStart;
15
use League\CommonMark\Parser\Block\BlockStartParserInterface;
16
use League\CommonMark\Parser\Cursor;
17
use League\CommonMark\Parser\MarkdownParserStateInterface;
18
19
final class FencedCodeStartParser implements BlockStartParserInterface
20
{
21 1899
    public function tryStart(Cursor $cursor, MarkdownParserStateInterface $parserState): ?BlockStart
22
    {
23 1899
        if ($cursor->isIndented()) {
24 183
            return BlockStart::none();
25
        }
26
27 1800
        $c = $cursor->getCharacter();
28 1800
        if ($c !== ' ' && $c !== "\t" && $c !== '`' && $c !== '~') {
29 1575
            return BlockStart::none();
30
        }
31
32 294
        $indent = $cursor->getIndent();
33 294
        $fence = $cursor->match('/^[ \t]*(?:`{3,}(?!.*`)|^~{3,})/');
34 294
        if ($fence === null) {
35 189
            return BlockStart::none();
36
        }
37
38
        // fenced code block
39 105
        $fence = \ltrim($fence, " \t");
40 105
        $fenceLength = \strlen($fence);
41
42 105
        return BlockStart::of(new FencedCodeParser($fenceLength, $fence[0], $indent))->at($cursor);
43
    }
44
}
45