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

EntityParser   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 5
dl 0
loc 18
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getCharacters() 0 4 1
A parse() 0 10 2
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