Passed
Push — latest ( 3af091...d64e46 )
by Colin
03:49 queued 01:39
created

src/Parser/Block/ParagraphParser.php (1 issue)

Labels
Severity
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 implements BlockContinueParserWithInlinesInterface
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 2604
    public function __construct()
40
    {
41 2604
        $this->block           = new Paragraph();
42 2604
        $this->referenceParser = new ReferenceParser();
43 2604
    }
44
45 414
    public function canHaveLazyContinuationLines(): bool
46
    {
47 414
        return true;
48
    }
49
50
    /**
51
     * @return Paragraph
52
     */
53 2604
    public function getBlock(): AbstractBlock
54
    {
55 2604
        return $this->block;
56
    }
57
58 1047
    public function tryContinue(Cursor $cursor, BlockContinueParserInterface $activeBlockParser): ?BlockContinue
59
    {
60 1047
        if ($cursor->isBlank()) {
61 645
            return BlockContinue::none();
1 ignored issue
show
Are you sure the usage of League\CommonMark\Parser...k\BlockContinue::none() targeting League\CommonMark\Parser...k\BlockContinue::none() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

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.

Loading history...
62
        }
63
64 576
        return BlockContinue::at($cursor);
65
    }
66
67 2604
    public function addLine(string $line): void
68
    {
69 2604
        $this->referenceParser->parse($line);
70 2604
    }
71
72 2496
    public function closeBlock(): void
73
    {
74 2496
        if ($this->referenceParser->hasReferences() && $this->referenceParser->getParagraphContent() === '') {
75 225
            $this->block->detach();
76
        }
77 2496
    }
78
79 2496
    public function parseInlines(InlineParserEngineInterface $inlineParser): void
80
    {
81 2496
        $content = $this->getContentString();
82 2496
        if ($content !== '') {
83 2490
            $inlineParser->parse($content, $this->block);
84
        }
85 2496
    }
86
87 2604
    public function getContentString(): string
88
    {
89 2604
        return $this->referenceParser->getParagraphContent();
90
    }
91
92
    /**
93
     * @return ReferenceInterface[]
94
     */
95 2604
    public function getReferences(): iterable
96
    {
97 2604
        return $this->referenceParser->getReferences();
98
    }
99
}
100