ListItem   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
lcom 2
cbo 3
dl 0
loc 70
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

6 Methods

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