1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the league/commonmark package. |
7
|
|
|
* |
8
|
|
|
* (c) Colin O'Dell <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace League\CommonMark\Parser\Block; |
15
|
|
|
|
16
|
|
|
use League\CommonMark\Node\Block\AbstractBlock; |
17
|
|
|
use League\CommonMark\Node\Block\Paragraph; |
18
|
|
|
use League\CommonMark\Parser\Cursor; |
19
|
|
|
use League\CommonMark\Parser\InlineParserEngineInterface; |
20
|
|
|
use League\CommonMark\Reference\ReferenceInterface; |
21
|
|
|
use League\CommonMark\Reference\ReferenceParser; |
22
|
|
|
|
23
|
|
|
final class ParagraphParser extends AbstractBlockContinueParser |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var Paragraph |
27
|
|
|
* |
28
|
|
|
* @psalm-readonly |
29
|
|
|
*/ |
30
|
|
|
private $block; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var ReferenceParser |
34
|
|
|
* |
35
|
|
|
* @psalm-readonly |
36
|
|
|
*/ |
37
|
|
|
private $referenceParser; |
38
|
|
|
|
39
|
2463 |
|
public function __construct() |
40
|
|
|
{ |
41
|
2463 |
|
$this->block = new Paragraph(); |
42
|
2463 |
|
$this->referenceParser = new ReferenceParser(); |
43
|
2463 |
|
} |
44
|
|
|
|
45
|
57 |
|
public function canHaveLazyContinuationLines(): bool |
46
|
|
|
{ |
47
|
57 |
|
return true; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return Paragraph |
52
|
|
|
*/ |
53
|
2463 |
|
public function getBlock(): AbstractBlock |
54
|
|
|
{ |
55
|
2463 |
|
return $this->block; |
56
|
|
|
} |
57
|
|
|
|
58
|
972 |
|
public function tryContinue(Cursor $cursor, BlockContinueParserInterface $activeBlockParser): ?BlockContinue |
59
|
|
|
{ |
60
|
972 |
|
if ($cursor->isBlank()) { |
61
|
582 |
|
return BlockContinue::none(); |
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
531 |
|
return BlockContinue::at($cursor); |
65
|
|
|
} |
66
|
|
|
|
67
|
2463 |
|
public function addLine(string $line): void |
68
|
|
|
{ |
69
|
2463 |
|
$this->referenceParser->parse($line); |
70
|
2463 |
|
} |
71
|
|
|
|
72
|
2358 |
|
public function closeBlock(): void |
73
|
|
|
{ |
74
|
2358 |
|
if ($this->referenceParser->hasReferences() && $this->referenceParser->getParagraphContent() === '') { |
75
|
225 |
|
$this->block->detach(); |
76
|
|
|
} |
77
|
2358 |
|
} |
78
|
|
|
|
79
|
2358 |
|
public function parseInlines(InlineParserEngineInterface $inlineParser): void |
80
|
|
|
{ |
81
|
2358 |
|
$content = $this->getContentString(); |
82
|
2358 |
|
if ($content !== '') { |
83
|
2352 |
|
$inlineParser->parse($content, $this->block); |
84
|
|
|
} |
85
|
2358 |
|
} |
86
|
|
|
|
87
|
2463 |
|
public function getContentString(): string |
88
|
|
|
{ |
89
|
2463 |
|
return $this->referenceParser->getParagraphContent(); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return ReferenceInterface[] |
94
|
|
|
*/ |
95
|
2463 |
|
public function getReferences(): iterable |
96
|
|
|
{ |
97
|
2463 |
|
return $this->referenceParser->getReferences(); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.