BlockStart   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 14
dl 0
loc 86
ccs 19
cts 19
cp 1
rs 10
c 1
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A at() 0 5 1
A of() 0 3 1
A __construct() 0 3 1
A getCursorState() 0 3 1
A isReplaceActiveBlockParser() 0 3 1
A getBlockParsers() 0 3 1
A replaceActiveBlockParser() 0 5 1
A none() 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\Block;
15
16
use League\CommonMark\Parser\Cursor;
17
use League\CommonMark\Parser\CursorState;
18
19
/**
20
 * Result object for starting parsing of a block; see static methods for constructors
21
 */
22
final class BlockStart
23
{
24
    /**
25
     * @var BlockContinueParserInterface[]
26
     *
27
     * @psalm-readonly
28
     */
29
    private $blockParsers;
30
31
    /**
32
     * @var CursorState|null
33
     *
34
     * @psalm-readonly-allow-private-mutation
35
     */
36
    private $cursorState = null;
37
38
    /**
39
     * @var bool
40
     *
41
     * @psalm-readonly-allow-private-mutation
42
     */
43
    private $replaceActiveBlockParser = false;
44
45 1134
    private function __construct(BlockContinueParserInterface ...$blockParsers)
46
    {
47 1134
        $this->blockParsers = $blockParsers;
48 1134
    }
49
50
    /**
51
     * @return BlockContinueParserInterface[]
52
     */
53 1134
    public function getBlockParsers(): iterable
54
    {
55 1134
        return $this->blockParsers;
56
    }
57
58 1116
    public function getCursorState(): ?CursorState
59
    {
60 1116
        return $this->cursorState;
61
    }
62
63 1116
    public function isReplaceActiveBlockParser(): bool
64
    {
65 1116
        return $this->replaceActiveBlockParser;
66
    }
67
68
    /**
69
     * Signal that we want to parse at the given cursor position
70
     *
71
     * @return $this
72
     */
73 1134
    public function at(Cursor $cursor): self
74
    {
75 1134
        $this->cursorState = $cursor->saveState();
76
77 1134
        return $this;
78
    }
79
80
    /**
81
     * Signal that we want to replace the active block parser with this one
82
     *
83
     * @return $this
84
     */
85 180
    public function replaceActiveBlockParser(): self
86
    {
87 180
        $this->replaceActiveBlockParser = true;
88
89 180
        return $this;
90
    }
91
92
    /**
93
     * Signal that we cannot parse whatever is here
94
     *
95
     * @return null
96
     */
97 2292
    public static function none(): ?self
98
    {
99 2292
        return null;
100
    }
101
102
    /**
103
     * Signal that we'd like to register the given parser(s) so they can parse the current block
104
     */
105 1134
    public static function of(BlockContinueParserInterface ...$blockParsers): self
106
    {
107 1134
        return new self(...$blockParsers);
108
    }
109
}
110