Completed
Pull Request — master (#8)
by
unknown
08:47
created

AttributesBlockParser::parse()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 6.4624

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 3
cts 11
cp 0.2727
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 11
nc 3
nop 2
crap 6.4624
1
<?php
2
3
/*
4
 * This is part of the webuni/commonmark-attributes-extension package.
5
 *
6
 * (c) Martin Hasoň <[email protected]>
7
 * (c) Webuni s.r.o. <[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
namespace Webuni\CommonMark\AttributesExtension;
14
15
use League\CommonMark\Block\Parser\AbstractBlockParser;
16
use League\CommonMark\ContextInterface;
17
use League\CommonMark\Cursor;
18
19
class AttributesBlockParser extends AbstractBlockParser
20
{
21 5
    public function parse(ContextInterface $context, Cursor $cursor)
22
    {
23 5
        $state = $cursor->saveState();
24 5
        $attributes = AttributesUtils::parse($cursor);
25
        if (empty($attributes)) {
26
            return false;
27
        }
28
29
        if (null !== $cursor->getNextNonSpaceCharacter()) {
30
            $cursor->restoreState($state);
31
32
            return false;
33
        }
34
35
        $context->addBlock(new Attributes($attributes));
36
        $context->setBlocksParsed(true);
37
38
        return true;
39
    }
40
}
41