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

BlockStart::replaceActiveBlockParser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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