AttributesBlockStartParser   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 8
dl 0
loc 16
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A tryStart() 0 14 4
1
<?php
2
3
/*
4
 * This file is part of the league/commonmark package.
5
 *
6
 * (c) Colin O'Dell <[email protected]>
7
 * (c) 2015 Martin Hasoň <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
declare(strict_types=1);
14
15
namespace League\CommonMark\Extension\Attributes\Parser;
16
17
use League\CommonMark\Extension\Attributes\Util\AttributesHelper;
18
use League\CommonMark\Parser\Block\BlockStart;
19
use League\CommonMark\Parser\Block\BlockStartParserInterface;
20
use League\CommonMark\Parser\Cursor;
21
use League\CommonMark\Parser\MarkdownParserStateInterface;
22
23
final class AttributesBlockStartParser implements BlockStartParserInterface
24
{
25
    public function tryStart(Cursor $cursor, MarkdownParserStateInterface $parserState): ?BlockStart
26
    {
27
        $originalPosition = $cursor->getPosition();
28
        $attributes       = AttributesHelper::parseAttributes($cursor);
29
30
        if ($attributes === [] && $originalPosition === $cursor->getPosition()) {
31
            return BlockStart::none();
32
        }
33
34
        if ($cursor->getNextNonSpaceCharacter() !== null) {
35
            return BlockStart::none();
36
        }
37
38
        return BlockStart::of(new AttributesBlockContinueParser($attributes, $parserState->getActiveBlockParser()->getBlock()))->at($cursor);
39
    }
40
}
41