Completed
Push — master ( d2636b...e88807 )
by Colin
02:51
created

ListItem::matchesNextLine()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 16
ccs 10
cts 10
cp 1
rs 9.2
c 1
b 0
f 0
cc 4
eloc 10
nc 4
nop 1
crap 4
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 240
    public function __construct(ListData $listData)
27
    {
28 240
        parent::__construct();
29
30 240
        $this->listData = $listData;
31 240
    }
32
33
    /**
34
     * Returns true if this block can contain the given block as a child node
35
     *
36
     * @param AbstractBlock $block
37
     *
38
     * @return bool
39
     */
40 231
    public function canContain(AbstractBlock $block)
41
    {
42 231
        return true;
43
    }
44
45
    /**
46
     * Returns true if block type can accept lines of text
47
     *
48
     * @return bool
49
     */
50 237
    public function acceptsLines()
51
    {
52 237
        return false;
53
    }
54
55
    /**
56
     * Whether this is a code block
57
     *
58
     * @return bool
59
     */
60 237
    public function isCode()
61
    {
62 237
        return false;
63
    }
64
65 204
    public function matchesNextLine(Cursor $cursor)
66
    {
67 204
        if ($cursor->isBlank()) {
68 120
            if ($this->firstChild === null) {
69 6
                return false;
70
            }
71
72 114
            $cursor->advanceToNextNonSpaceOrTab();
73 201
        } elseif ($cursor->getIndent() >= $this->listData->markerOffset + $this->listData->padding) {
74 120
            $cursor->advanceBy($this->listData->markerOffset + $this->listData->padding, true);
75 80
        } else {
76 120
            return false;
77
        }
78
79 144
        return true;
80
    }
81
82
    /**
83
     * @param Cursor $cursor
84
     * @param int    $currentLineNumber
85
     *
86
     * @return bool
87
     */
88 228
    public function shouldLastLineBeBlank(Cursor $cursor, $currentLineNumber)
89
    {
90 228
        return $cursor->isBlank() && $this->startLine < $currentLineNumber;
91
    }
92
}
93