AttributesBlockParser::parse()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

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 3
nc 3
nop 2
crap 3
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This is part of the webuni/commonmark-attributes-extension package.
7
 *
8
 * (c) Martin Hasoň <[email protected]>
9
 * (c) Webuni s.r.o. <[email protected]>
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 Webuni\CommonMark\AttributesExtension;
16
17
use League\CommonMark\Block\Parser\BlockParserInterface;
18
use League\CommonMark\ContextInterface;
19
use League\CommonMark\Cursor;
20
21 5
final class AttributesBlockParser implements BlockParserInterface
22
{
23 5
    public function parse(ContextInterface $context, Cursor $cursor): bool
24 5
    {
25 5
        $state = $cursor->saveState();
26 4
        $attributes = AttributesUtils::parse($cursor);
27
        if (empty($attributes)) {
28
            return false;
29 5
        }
30 3
31
        if (null !== $cursor->getNextNonSpaceCharacter()) {
32 3
            $cursor->restoreState($state);
33
34
            return false;
35 5
        }
36 5
37
        $context->addBlock(new Attributes($attributes));
38 5
        $context->setBlocksParsed(true);
39
40
        return true;
41
    }
42
}
43