Completed
Push — master ( da0d4f...97e8b3 )
by Colin
03:00
created

Heading   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 0
loc 77
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getLevel() 0 4 1
A finalize() 0 6 1
A __construct() 0 14 3
A matchesNextLine() 0 4 1
A handleRemainingContents() 0 4 1
A canContain() 0 4 1
A isCode() 0 4 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\Block\Element;
16
17
use League\CommonMark\ContextInterface;
18
use League\CommonMark\Cursor;
19
20
class Heading extends AbstractStringContainerBlock implements InlineContainerInterface
21
{
22
    /**
23
     * @var int
24
     */
25
    protected $level;
26
27
    /**
28
     * @param int             $level
29
     * @param string|string[] $contents
30
     */
31 159
    public function __construct(int $level, $contents)
32
    {
33 159
        parent::__construct();
34
35 159
        $this->level = $level;
36
37 159
        if (!\is_array($contents)) {
38 111
            $contents = [$contents];
39
        }
40
41 159
        foreach ($contents as $line) {
42 159
            $this->addLine($line);
43
        }
44 159
    }
45
46
    /**
47
     * @return int
48
     */
49 150
    public function getLevel(): int
50
    {
51 150
        return $this->level;
52
    }
53
54 129
    public function finalize(ContextInterface $context, int $endLineNumber)
55
    {
56 129
        parent::finalize($context, $endLineNumber);
57
58 129
        $this->finalStringContents = \implode("\n", $this->strings->toArray());
59 129
    }
60
61
    /**
62
     * Returns true if this block can contain the given block as a child node
63
     *
64
     * @param AbstractBlock $block
65
     *
66
     * @return bool
67
     */
68 3
    public function canContain(AbstractBlock $block): bool
69
    {
70 3
        return false;
71
    }
72
73
    /**
74
     * Whether this is a code block
75
     *
76
     * @return bool
77
     */
78 3
    public function isCode(): bool
79
    {
80 3
        return false;
81
    }
82
83 81
    public function matchesNextLine(Cursor $cursor): bool
84
    {
85 81
        return false;
86
    }
87
88
    /**
89
     * @param ContextInterface $context
90
     * @param Cursor           $cursor
91
     */
92 129
    public function handleRemainingContents(ContextInterface $context, Cursor $cursor)
93
    {
94
        // nothing to do; contents were already added via the constructor.
95 129
    }
96
}
97