AttributesInlineParser   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 14
c 1
b 0
f 0
dl 0
loc 28
ccs 15
cts 15
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getMatchDefinition() 0 3 1
A parse() 0 21 5
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\Extension\Attributes\Node\AttributesInline;
18
use League\CommonMark\Extension\Attributes\Util\AttributesHelper;
19
use League\CommonMark\Parser\Inline\InlineParserInterface;
20
use League\CommonMark\Parser\Inline\InlineParserMatch;
21
use League\CommonMark\Parser\InlineParserContext;
22
23
final class AttributesInlineParser implements InlineParserInterface
24
{
25 18
    public function getMatchDefinition(): InlineParserMatch
26
    {
27 18
        return InlineParserMatch::oneOf(' ', '{');
28
    }
29
30 15
    public function parse(InlineParserContext $inlineContext): bool
31
    {
32 15
        $char   = $inlineContext->getFullMatch();
33 15
        $cursor = $inlineContext->getCursor();
34 15
        if ($char === '{') {
35 15
            $char = (string) $cursor->peek(-1);
36
        }
37
38 15
        $attributes = AttributesHelper::parseAttributes($cursor);
39 15
        if ($attributes === []) {
40 12
            return false;
41
        }
42
43 15
        if ($char === '') {
44 9
            $cursor->advanceToNextNonSpaceOrNewline();
45
        }
46
47 15
        $node = new AttributesInline($attributes, $char === ' ' || $char === '');
48 15
        $inlineContext->getContainer()->appendChild($node);
49
50 15
        return true;
51
    }
52
}
53