MarkdownParserState   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 12
dl 0
loc 42
ccs 14
cts 14
cp 1
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getLastMatchedBlockParser() 0 3 1
A getParagraphContent() 0 10 3
A __construct() 0 4 1
A getActiveBlockParser() 0 3 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
    /**
25
     * @var BlockContinueParserInterface
26
     *
27
     * @psalm-readonly
28
     */
29
    private $activeBlockParser;
30
31
    /**
32
     * @var BlockContinueParserInterface
33
     *
34
     * @psalm-readonly
35
     */
36
    private $lastMatchedBlockParser;
37
38 2340
    public function __construct(BlockContinueParserInterface $activeBlockParser, BlockContinueParserInterface $lastMatchedBlockParser)
39
    {
40 2340
        $this->activeBlockParser      = $activeBlockParser;
41 2340
        $this->lastMatchedBlockParser = $lastMatchedBlockParser;
42 2340
    }
43
44 237
    public function getActiveBlockParser(): BlockContinueParserInterface
45
    {
46 237
        return $this->activeBlockParser;
47
    }
48
49 393
    public function getLastMatchedBlockParser(): BlockContinueParserInterface
50
    {
51 393
        return $this->lastMatchedBlockParser;
52
    }
53
54 1734
    public function getParagraphContent(): ?string
55
    {
56 1734
        if (! $this->lastMatchedBlockParser instanceof ParagraphParser) {
57 1629
            return null;
58
        }
59
60 360
        $paragraphParser = $this->lastMatchedBlockParser;
61 360
        $content         = $paragraphParser->getContentString();
62
63 360
        return $content === '' ? null : $content;
64
    }
65
}
66