Completed
Push — master ( 0b0b24...54ff37 )
by Colin
02:37
created

EntityParser::getCharacters()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
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
 *
8
 * Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
9
 *  - (c) John MacFarlane
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 */
14
15
namespace League\CommonMark\Extension\CommonMark\Parser\Inline;
16
17
use League\CommonMark\Node\Inline\Text;
18
use League\CommonMark\Parser\Inline\InlineParserInterface;
19
use League\CommonMark\Parser\InlineParserContext;
20
use League\CommonMark\Util\Html5EntityDecoder;
21
use League\CommonMark\Util\RegexHelper;
22
23
final class EntityParser implements InlineParserInterface
24
{
25 2490
    public function getCharacters(): array
26
    {
27 2490
        return ['&'];
28
    }
29
30 57
    public function parse(InlineParserContext $inlineContext): bool
31
    {
32 57
        if ($m = $inlineContext->getCursor()->match('/^' . RegexHelper::PARTIAL_ENTITY . '/i')) {
33 42
            $inlineContext->getContainer()->appendChild(new Text(Html5EntityDecoder::decode($m)));
34
35 42
            return true;
36
        }
37
38 24
        return false;
39
    }
40
}
41