Completed
Push — latest ( 609def...dcbb7e )
by Colin
14s queued 11s
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
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 2499
    public function __construct()
40
    {
41 2499
        $this->block           = new Paragraph();
42 2499
        $this->referenceParser = new ReferenceParser();
43 2499
    }
44
45 57
    public function canHaveLazyContinuationLines(): bool
46
    {
47 57
        return true;
48
    }
49
50
    /**
51
     * @return Paragraph
52
     */
53 2499
    public function getBlock(): AbstractBlock
54
    {
55 2499
        return $this->block;
56
    }
57
58 981
    public function tryContinue(Cursor $cursor, BlockContinueParserInterface $activeBlockParser): ?BlockContinue
59
    {
60 981
        if ($cursor->isBlank()) {
61 591
            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 531
        return BlockContinue::at($cursor);
65
    }
66
67 2499
    public function addLine(string $line): void
68
    {
69 2499
        $this->referenceParser->parse($line);
70 2499
    }
71
72 2394
    public function closeBlock(): void
73
    {
74 2394
        if ($this->referenceParser->hasReferences() && $this->referenceParser->getParagraphContent() === '') {
75 225
            $this->block->detach();
76
        }
77 2394
    }
78
79 2394
    public function parseInlines(InlineParserEngineInterface $inlineParser): void
80
    {
81 2394
        $content = $this->getContentString();
82 2394
        if ($content !== '') {
83 2388
            $inlineParser->parse($content, $this->block);
84
        }
85 2394
    }
86
87 2499
    public function getContentString(): string
88
    {
89 2499
        return $this->referenceParser->getParagraphContent();
90
    }
91
92
    /**
93
     * @return ReferenceInterface[]
94
     */
95 2499
    public function getReferences(): iterable
96
    {
97 2499
        return $this->referenceParser->getReferences();
98
    }
99
}
100