Passed
Push — latest ( d59ff4...6fb795 )
by Colin
08:12
created

AttributesInlineParser::getCharacters()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 0
crap 1
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\InlineParserContext;
21
22
final class AttributesInlineParser implements InlineParserInterface
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27 18
    public function getCharacters(): array
28
    {
29 18
        return [' ', '{'];
30
    }
31
32 15
    public function parse(InlineParserContext $inlineContext): bool
33
    {
34 15
        $cursor = $inlineContext->getCursor();
35 15
        if ($cursor->getNextNonSpaceCharacter() !== '{') {
36 12
            return false;
37
        }
38
39 15
        $char = $cursor->getCharacter();
40 15
        if ($char === '{') {
41 15
            $char = (string) $cursor->getCharacter($cursor->getPosition() - 1);
42
        }
43
44 15
        $attributes = AttributesHelper::parseAttributes($cursor);
45 15
        if ($attributes === []) {
46 3
            return false;
47
        }
48
49 15
        if ($char === '') {
50 9
            $cursor->advanceToNextNonSpaceOrNewline();
51
        }
52
53 15
        $node = new AttributesInline($attributes, $char === ' ' || $char === '');
54 15
        $inlineContext->getContainer()->appendChild($node);
55
56 15
        return true;
57
    }
58
}
59