Completed
Push — 1.5 ( fb52dd...2fb592 )
by Colin
02:48
created

AttributesBlockParser   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 4
dl 0
loc 24
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A parse() 0 19 3
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\Block\Parser\BlockParserInterface;
18
use League\CommonMark\ContextInterface;
19
use League\CommonMark\Cursor;
20
use League\CommonMark\Extension\Attributes\Node\Attributes;
21
22
final class AttributesBlockParser implements BlockParserInterface
23
{
24
    use AttributesParserTrait;
25
26 18
    public function parse(ContextInterface $context, Cursor $cursor): bool
27
    {
28 18
        $state = $cursor->saveState();
29 18
        $attributes = $this->parseAttributes($cursor);
30 18
        if ($attributes === []) {
31 15
            return false;
32
        }
33
34 15
        if ($cursor->getNextNonSpaceCharacter() !== null) {
35 9
            $cursor->restoreState($state);
36
37 9
            return false;
38
        }
39
40 15
        $context->addBlock(new Attributes($attributes));
41 15
        $context->setBlocksParsed(true);
42
43 15
        return true;
44
    }
45
}
46