OpenBracketParser   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 6
dl 0
loc 32
ccs 10
cts 11
cp 0.9091
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getCharacters() 0 4 1
A parse() 0 16 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\Inline\Parser;
16
17
use League\CommonMark\Delimiter\Delimiter;
18
use League\CommonMark\Inline\Element\Text;
19
use League\CommonMark\InlineParserContext;
20
21
final class OpenBracketParser implements InlineParserInterface
22
{
23
    /**
24
     * @return string[]
25
     */
26 2064
    public function getCharacters(): array
27
    {
28 2064
        return ['['];
29
    }
30
31
    /**
32
     * @param InlineParserContext $inlineContext
33
     *
34
     * @return bool
35
     */
36 396
    public function parse(InlineParserContext $inlineContext): bool
37
    {
38 396
        if ($inlineContext->getCursor()->getCharacter() !== '[') {
39
            return false;
40
        }
41
42 396
        $inlineContext->getCursor()->advance();
43 396
        $node = new Text('[', ['delim' => true]);
44 396
        $inlineContext->getContainer()->appendChild($node);
45
46
        // Add entry to stack for this opener
47 396
        $delimiter = new Delimiter('[', 1, $node, true, false, $inlineContext->getCursor()->getPosition());
48 396
        $inlineContext->getDelimiterStack()->push($delimiter);
49
50 396
        return true;
51
    }
52
}
53