MarkdownParserState::getLastMatchedBlockParser()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
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;
15
16
use League\CommonMark\Parser\Block\BlockContinueParserInterface;
17
use League\CommonMark\Parser\Block\ParagraphParser;
18
19
/**
20
 * @internal You should rely on the interface instead
21
 */
22
final class MarkdownParserState implements MarkdownParserStateInterface
23
{
24
    /** @psalm-readonly */
25
    private BlockContinueParserInterface $activeBlockParser;
26
27
    /** @psalm-readonly */
28
    private BlockContinueParserInterface $lastMatchedBlockParser;
29
30 2304
    public function __construct(BlockContinueParserInterface $activeBlockParser, BlockContinueParserInterface $lastMatchedBlockParser)
31
    {
32 2304
        $this->activeBlockParser      = $activeBlockParser;
33 2304
        $this->lastMatchedBlockParser = $lastMatchedBlockParser;
34
    }
35
36 208
    public function getActiveBlockParser(): BlockContinueParserInterface
37
    {
38 208
        return $this->activeBlockParser;
39
    }
40
41 302
    public function getLastMatchedBlockParser(): BlockContinueParserInterface
42
    {
43 302
        return $this->lastMatchedBlockParser;
44
    }
45
46 1318
    public function getParagraphContent(): ?string
47
    {
48 1318
        if (! $this->lastMatchedBlockParser instanceof ParagraphParser) {
49 1234
            return null;
50
        }
51
52 276
        $paragraphParser = $this->lastMatchedBlockParser;
53 276
        $content         = $paragraphParser->getContentString();
0 ignored issues
show
Bug introduced by
The method getContentString() does not exist on League\CommonMark\Parser...ContinueParserInterface. It seems like you code against a sub-type of League\CommonMark\Parser...ContinueParserInterface such as League\CommonMark\Parser\Block\ParagraphParser or League\CommonMark\Parser\Block\ParagraphParser. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

53
        /** @scrutinizer ignore-call */ 
54
        $content         = $paragraphParser->getContentString();
Loading history...
54
55 276
        return $content === '' ? null : $content;
56
    }
57
}
58