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

AttributesBlockParser   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
c 3
b 0
f 0
lcom 0
cbo 5
dl 0
loc 22
ccs 11
cts 11
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A parse() 0 19 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