Completed
Push — feature/resolve-parent-class ( 1a8a55...248da8 )
by Colin
35:17 queued 33:54
created

OpenBracketParser::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\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 2463
    public function getCharacters(): array
27
    {
28 2463
        return ['['];
29
    }
30
31
    /**
32
     * @param InlineParserContext $inlineContext
33
     *
34
     * @return bool
35
     */
36 417
    public function parse(InlineParserContext $inlineContext): bool
37
    {
38 417
        $inlineContext->getCursor()->advanceBy(1);
39 417
        $node = new Text('[', ['delim' => true]);
40 417
        $inlineContext->getContainer()->appendChild($node);
41
42
        // Add entry to stack for this opener
43 417
        $delimiter = new Delimiter('[', 1, $node, true, false, $inlineContext->getCursor()->getPosition());
44 417
        $inlineContext->getDelimiterStack()->push($delimiter);
45
46 417
        return true;
47
    }
48
}
49