Completed
Push — master ( d2636b...e88807 )
by Colin
02:51
created

BangParser::parse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 17
ccs 10
cts 10
cp 1
rs 9.4285
cc 2
eloc 10
nc 2
nop 1
crap 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
class BangParser extends AbstractInlineParser
22
{
23
    /**
24
     * @return string[]
25
     */
26 1935
    public function getCharacters()
27
    {
28 1935
        return ['!'];
29
    }
30
31
    /**
32
     * @param InlineParserContext $inlineContext
33
     *
34
     * @return bool
35
     */
36 90
    public function parse(InlineParserContext $inlineContext)
37
    {
38 90
        $cursor = $inlineContext->getCursor();
39 90
        if ($cursor->peek() === '[') {
40 81
            $cursor->advanceBy(2);
41 81
            $node = new Text('![', ['delim' => true]);
42 81
            $inlineContext->getContainer()->appendChild($node);
43
44
            // Add entry to stack for this opener
45 81
            $delimiter = new Delimiter('!', 1, $node, true, false, $cursor->getPosition());
46 81
            $inlineContext->getDelimiterStack()->push($delimiter);
47
48 81
            return true;
49
        }
50
51 9
        return false;
52
    }
53
}
54