IconBlock::getIconBlockTypes()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1.037

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 8
cts 12
cp 0.6667
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1.037
1
<?php
2
3
/*
4
 * This file is part of the league/markua package.
5
 *
6
 * (c) Davey Shafik <[email protected]>
7
 * (c) Dan Hunsaker <[email protected]>
8
 *
9
 * Original code based on the CommonMark JS reference parser (http://bitly.com/commonmarkjs)
10
 *  - (c) John MacFarlane
11
 *
12
 * For the full copyright and license information, please view the LICENSE
13
 * file that was distributed with this source code.
14
 */
15
16
namespace Danhunsaker\Markua\Block\Element;
17
18
use League\CommonMark\Cursor;
19
20
class IconBlock extends Aside
21
{
22
    protected $type;
23
24
    /**
25
     * @param string $type Icon Block type (e.g. I for Info)
26
     */
27 23
    public function __construct($type)
28
    {
29 23
        parent::__construct();
30 23
        $this->type = $type;
31 23
    }
32
33
    /**
34
     * @return string
35
     */
36 23
    public function getType()
37
    {
38 23
        return $this->type;
39
    }
40
41
    /**
42
     * @return string
43
     */
44 23
    public function getTypeName()
45
    {
46 23
        $types = array_flip(static::getIconBlockTypes());
47 23
        return $types[$this->getType()];
48
    }
49
50
    /**
51
     * @return array
52
     */
53 30
    public static function getIconBlockTypes()
54
    {
55
        return array(
56 30
            'discussion' => 'D',
57 30
            'error' => 'E',
58 30
            'info' => 'I',
59 30
            'question' => 'Q',
60 30
            'tip' => 'T',
61 30
            'warning' => 'W',
62
            'exercise' => 'X'
63 30
        );
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69 16
    public function matchesNextLine(Cursor $cursor)
70
    {
71 16
        if ($cursor->getIndent() <= 3 && in_array($cursor->getNextNonSpaceCharacter(), static::getIconBlockTypes())) {
72 14
            $cursor->advanceToNextNonSpaceOrNewline();
73 14
            if ($cursor->peek() === '>') {
74 14
                $cursor->advanceBy(2);
75 14
                if ($cursor->getCharacter() === ' ') {
76 14
                    $cursor->advance();
77 14
                }
78 14
                return true;
79
            }
80
        }
81
82 2
        return false;
83
    }
84
}
85