Completed
Push — master ( b42489...8df37e )
by Colin
14s queued 11s
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\Inline\Parser;
16
17
use League\CommonMark\Inline\Element\Text;
18
use League\CommonMark\InlineParserContext;
19
use League\CommonMark\Util\Html5EntityDecoder;
20
use League\CommonMark\Util\RegexHelper;
21
22
final class EntityParser implements InlineParserInterface
23
{
24
    /**
25
     * @return string[]
26
     */
27 2070
    public function getCharacters(): array
28
    {
29 2070
        return ['&'];
30
    }
31
32
    /**
33
     * @param InlineParserContext $inlineContext
34
     *
35
     * @return bool
36
     */
37 48
    public function parse(InlineParserContext $inlineContext): bool
38
    {
39 48
        if ($inlineContext->getCursor()->getCharacter() !== '&') {
40
            return false;
41
        }
42
43 48
        if ($m = $inlineContext->getCursor()->match('/^' . RegexHelper::PARTIAL_ENTITY . '/i')) {
44 36
            $inlineContext->getContainer()->appendChild(new Text(Html5EntityDecoder::decode($m)));
45
46 36
            return true;
47
        }
48
49 18
        return false;
50
    }
51
}
52