Paragraph   A
last analyzed

Coupling/Cohesion

Components 2
Dependencies 4

Complexity

Total Complexity 14

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 14
lcom 2
cbo 4
dl 0
loc 94
ccs 34
cts 34
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A canContain() 0 4 1
A acceptsLines() 0 4 1
A isCode() 0 4 1
A matchesNextLine() 0 10 2
A parseReferences() 0 10 3
A handleRemainingContents() 0 5 1
B finalize() 0 21 5
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 Paragraph extends AbstractBlock implements InlineContainer
21
{
22
    /**
23
     * Returns true if this block can contain the given block as a child node
24
     *
25
     * @param AbstractBlock $block
26
     *
27
     * @return bool
28
     */
29 69
    public function canContain(AbstractBlock $block)
30
    {
31 69
        return false;
32
    }
33
34
    /**
35
     * Returns true if block type can accept lines of text
36
     *
37
     * @return bool
38
     */
39 1608
    public function acceptsLines()
40
    {
41 1608
        return true;
42
    }
43
44
    /**
45
     * Whether this is a code block
46
     *
47
     * @return bool
48
     */
49 357
    public function isCode()
50
    {
51 357
        return false;
52
    }
53
54 687
    public function matchesNextLine(Cursor $cursor)
55
    {
56 687
        if ($cursor->isBlank()) {
57 429
            $this->lastLineBlank = true;
58
59 429
            return false;
60
        }
61
62 357
        return true;
63
    }
64
65 1572
    public function finalize(ContextInterface $context, $endLineNumber)
66
    {
67 1572
        parent::finalize($context, $endLineNumber);
68
69 1572
        $this->finalStringContents = preg_replace('/^  */m', '', implode("\n", $this->getStrings()));
70
71
        // Short-circuit
72 1572
        if ($this->finalStringContents === '' || $this->finalStringContents[0] !== '[') {
73 1260
            return;
74
        }
75
76 390
        $cursor = new Cursor($this->finalStringContents);
77
78 390
        $referenceFound = $this->parseReferences($context, $cursor);
79
80 390
        $this->finalStringContents = $cursor->getRemainder();
81
82 390
        if ($referenceFound && $cursor->isAtEnd()) {
83 216
            $this->detach();
84 216
        }
85 390
    }
86
87
    /**
88
     * @param ContextInterface $context
89
     * @param Cursor           $cursor
90
     *
91
     * @return bool
92
     */
93 390
    protected function parseReferences(ContextInterface $context, Cursor $cursor)
94
    {
95 390
        $referenceFound = false;
96 390
        while ($cursor->getCharacter() === '[' && $context->getReferenceParser()->parse($cursor)) {
97 222
            $this->finalStringContents = $cursor->getRemainder();
98 222
            $referenceFound = true;
99 222
        }
100
101 390
        return $referenceFound;
102
    }
103
104
    /**
105
     * @param ContextInterface $context
106
     * @param Cursor           $cursor
107
     */
108 252
    public function handleRemainingContents(ContextInterface $context, Cursor $cursor)
109
    {
110 252
        $cursor->advanceToNextNonSpaceOrTab();
111 252
        $context->getTip()->addLine($cursor->getRemainder());
112 252
    }
113
}
114