Completed
Push — master ( bc1658...173073 )
by Colin
36:23 queued 33:33
created

ListItem   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
wmc 11
lcom 2
cbo 3
dl 0
loc 82
ccs 22
cts 24
cp 0.9167
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A isCode() 0 4 1
A getListData() 0 4 1
A canContain() 0 4 1
A acceptsLines() 0 4 1
A matchesNextLine() 0 16 4
A shouldLastLineBeBlank() 0 4 2
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
     * @return ListData
35
     */
36
    public function getListData()
37
    {
38
        return $this->listData;
39
    }
40
41
    /**
42
     * Returns true if this block can contain the given block as a child node
43
     *
44
     * @param AbstractBlock $block
45
     *
46
     * @return bool
47
     */
48 231
    public function canContain(AbstractBlock $block)
49
    {
50 231
        return true;
51
    }
52
53
    /**
54
     * Returns true if block type can accept lines of text
55
     *
56
     * @return bool
57
     */
58 237
    public function acceptsLines()
59
    {
60 237
        return false;
61
    }
62
63
    /**
64
     * Whether this is a code block
65
     *
66
     * @return bool
67
     */
68 237
    public function isCode()
69
    {
70 237
        return false;
71
    }
72
73 204
    public function matchesNextLine(Cursor $cursor)
74
    {
75 204
        if ($cursor->isBlank()) {
76 120
            if ($this->firstChild === null) {
77 6
                return false;
78
            }
79
80 114
            $cursor->advanceToNextNonSpaceOrTab();
81 201
        } elseif ($cursor->getIndent() >= $this->listData->markerOffset + $this->listData->padding) {
82 120
            $cursor->advanceBy($this->listData->markerOffset + $this->listData->padding, true);
83 40
        } else {
84 120
            return false;
85
        }
86
87 144
        return true;
88
    }
89
90
    /**
91
     * @param Cursor $cursor
92
     * @param int    $currentLineNumber
93
     *
94
     * @return bool
95
     */
96 228
    public function shouldLastLineBeBlank(Cursor $cursor, $currentLineNumber)
97
    {
98 228
        return $cursor->isBlank() && $this->startLine < $currentLineNumber;
99
    }
100
}
101