Completed
Branch master (5a127a)
by Martin
02:17
created

AttributesBlockParser::parse()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 19
ccs 11
cts 11
cp 1
rs 9.4285
cc 3
eloc 11
nc 3
nop 2
crap 3
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 5
        if (empty($attributes)) {
26 4
            return false;
27
        }
28
29 5
        if (null !== $cursor->getFirstNonSpaceCharacter()) {
30 3
            $cursor->restoreState($state);
31
32 3
            return false;
33
        }
34
35 5
        $context->addBlock(new Attributes($attributes));
36 5
        $context->setBlocksParsed(true);
37
38 5
        return true;
39
    }
40
}
41