IndentedCodeStartParser::tryStart()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4.0218

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 17
ccs 8
cts 9
cp 0.8889
rs 10
c 1
b 0
f 0
cc 4
nc 4
nop 2
crap 4.0218
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the league/commonmark package.
7
 *
8
 * (c) Colin O'Dell <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace League\CommonMark\Extension\CommonMark\Parser\Block;
15
16
use League\CommonMark\Node\Block\Paragraph;
17
use League\CommonMark\Parser\Block\BlockStart;
18
use League\CommonMark\Parser\Block\BlockStartParserInterface;
19
use League\CommonMark\Parser\Cursor;
20
use League\CommonMark\Parser\MarkdownParserStateInterface;
21
22
final class IndentedCodeStartParser implements BlockStartParserInterface
23
{
24 1542
    public function tryStart(Cursor $cursor, MarkdownParserStateInterface $parserState): ?BlockStart
25
    {
26 1542
        if (! $cursor->isIndented()) {
27 1356
            return BlockStart::none();
28
        }
29
30 195
        if ($parserState->getActiveBlockParser()->getBlock() instanceof Paragraph) {
31 39
            return BlockStart::none();
32
        }
33
34 156
        if ($cursor->isBlank()) {
35
            return BlockStart::none();
36
        }
37
38 156
        $cursor->advanceBy(Cursor::INDENT_LEVEL, true);
39
40 156
        return BlockStart::of(new IndentedCodeParser())->at($cursor);
41
    }
42
}
43