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

ListItem::getListData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 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\Cursor;
18
19
class ListItem extends AbstractBlock
20
{
21
    /**
22
     * @var ListData
23
     */
24
    protected $listData;
25
26 252
    public function __construct(ListData $listData)
27
    {
28 252
        $this->listData = $listData;
29 252
    }
30
31
    /**
32
     * @return ListData
33
     */
34 3
    public function getListData(): ListData
35
    {
36 3
        return $this->listData;
37
    }
38
39
    /**
40
     * Returns true if this block can contain the given block as a child node
41
     *
42
     * @param AbstractBlock $block
43
     *
44
     * @return bool
45
     */
46 240
    public function canContain(AbstractBlock $block): bool
47
    {
48 240
        return true;
49
    }
50
51
    /**
52
     * Whether this is a code block
53
     *
54
     * @return bool
55
     */
56 246
    public function isCode(): bool
57
    {
58 246
        return false;
59
    }
60
61 210
    public function matchesNextLine(Cursor $cursor): bool
62
    {
63 210
        if ($cursor->isBlank()) {
64 123
            if ($this->firstChild === null) {
65 6
                return false;
66
            }
67
68 117
            $cursor->advanceToNextNonSpaceOrTab();
69 207
        } elseif ($cursor->getIndent() >= $this->listData->markerOffset + $this->listData->padding) {
70 120
            $cursor->advanceBy($this->listData->markerOffset + $this->listData->padding, true);
71
        } else {
72 126
            return false;
73
        }
74
75 147
        return true;
76
    }
77
78
    /**
79
     * @param Cursor $cursor
80
     * @param int    $currentLineNumber
81
     *
82
     * @return bool
83
     */
84 237
    public function shouldLastLineBeBlank(Cursor $cursor, int $currentLineNumber): bool
85
    {
86 237
        return $cursor->isBlank() && $this->startLine < $currentLineNumber;
87
    }
88
}
89