Completed
Push — refactor-parsing ( adbb6b...fbe6de )
by Colin
08:21 queued 07:01
created

MarkdownParserState::getLastMatchedBlockParser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
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
/*
4
 * This file is part of the league/commonmark package.
5
 *
6
 * (c) Colin O'Dell <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace League\CommonMark\Parser;
13
14
use League\CommonMark\Parser\Block\BlockContinueParserInterface;
15
use League\CommonMark\Parser\Block\ParagraphParser;
16
17
/**
18
 * @internal You should rely on the interface instead
19
 */
20
final class MarkdownParserState implements MarkdownParserStateInterface
21
{
22
    /** @var BlockContinueParserInterface */
23
    private $activeBlockParser;
24
25
    /** @var BlockContinueParserInterface */
26
    private $lastMatchedBlockParser;
27
28 2109
    public function __construct(BlockContinueParserInterface $activeBlockParser, BlockContinueParserInterface $lastMatchedBlockParser)
29
    {
30 2109
        $this->activeBlockParser = $activeBlockParser;
31 2109
        $this->lastMatchedBlockParser = $lastMatchedBlockParser;
32 2109
    }
33
34 183
    public function getActiveBlockParser(): BlockContinueParserInterface
35
    {
36 183
        return $this->activeBlockParser;
37
    }
38
39 306
    public function getLastMatchedBlockParser(): BlockContinueParserInterface
40
    {
41 306
        return $this->lastMatchedBlockParser;
42
    }
43
44 1596
    public function getParagraphContent(): ?string
45
    {
46 1596
        if (!$this->lastMatchedBlockParser instanceof ParagraphParser) {
47 1515
            return null;
48
        }
49
50
        /** @var ParagraphParser $paragraphParser */
51 300
        $paragraphParser = $this->lastMatchedBlockParser;
52 300
        $content = $paragraphParser->getContentString();
53
54 300
        return $content === '' ? null : $content;
55
    }
56
}
57