IconBlockParser   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 82.35%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 4
dl 0
loc 30
ccs 14
cts 17
cp 0.8235
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A parse() 0 21 5
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