Completed
Push — master ( 0b0b24...54ff37 )
by Colin
02:37
created

IndentedCodeParser::parse()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 10
cts 10
cp 1
rs 9.6333
c 0
b 0
f 0
cc 4
nc 4
nop 2
crap 4
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\Extension\CommonMark\Parser\Block;
16
17
use League\CommonMark\Extension\CommonMark\Node\Block\IndentedCode;
18
use League\CommonMark\Node\Block\Paragraph;
19
use League\CommonMark\Parser\Block\BlockParserInterface;
20
use League\CommonMark\Parser\ContextInterface;
21
use League\CommonMark\Parser\Cursor;
22
23
final class IndentedCodeParser implements BlockParserInterface
24
{
25 2235
    public function parse(ContextInterface $context, Cursor $cursor): bool
26
    {
27 2235
        if (!$cursor->isIndented()) {
28 2169
            return false;
29
        }
30
31 183
        if ($context->getTip() instanceof Paragraph) {
32 33
            return false;
33
        }
34
35 150
        if ($cursor->isBlank()) {
36 3
            return false;
37
        }
38
39 150
        $cursor->advanceBy(Cursor::INDENT_LEVEL, true);
40 150
        $context->addBlock(new IndentedCode());
41
42 150
        return true;
43
    }
44
}
45