IconBlockParser::parse()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 5.1374

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 14
cts 17
cp 0.8235
rs 9.2728
c 0
b 0
f 0
cc 5
nc 4
nop 2
crap 5.1374
1
<?php
2
3
/*
4
 * This file is part of the league/commonmark package.
5
 *
6
 * (c) Davey Shafik <[email protected]
7
 * (c) Colin O'Dell <[email protected]>
8
 * (c) Dan Hunsaker <[email protected]>
9
 *
10
 * Original code based on the CommonMark JS reference parser (http://bitly.com/commonmarkjs)
11
 *  - (c) John MacFarlane
12
 *
13
 * For the full copyright and license information, please view the LICENSE
14
 * file that was distributed with this source code.
15
 */
16
17
namespace Danhunsaker\Markua\Block\Parser;
18
19
use League\CommonMark\Block\Parser\AbstractBlockParser;
20
use League\CommonMark\ContextInterface;
21
use League\CommonMark\Cursor;
22
use Danhunsaker\Markua\Block\Element\IconBlock;
23
24
class IconBlockParser extends AbstractBlockParser
25
{
26
    /**
27
     * @param ContextInterface $context
28
     * @param Cursor $cursor
29
     *
30
     * @return bool
31
     */
32 30
    public function parse(ContextInterface $context, Cursor $cursor)
33
    {
34 30
        if (!in_array($cursor->getNextNonSpaceCharacter(), IconBlock::getIconBlockTypes()) ||
35 30
            $cursor->getCharacter($cursor->getNextNonSpacePosition() + 1) !== '>') {
36 30
            return false;
37
        }
38
39 23
        $type = $cursor->getNextNonSpaceCharacter();
40
41 23
        $cursor->advanceToNextNonSpaceOrNewline();
42 23
        if ($cursor->peek() === '>') {
43 23
            $cursor->advanceBy(2);
44 23
            if ($cursor->getCharacter() === ' ') {
45 23
                $cursor->advance();
46 23
            }
47 23
        }
48
49 23
        $context->addBlock(new IconBlock($type));
50
51 23
        return true;
52
    }
53
}
54