Completed
Push — master ( 15e8d5...9ebb39 )
by Colin
04:59
created

MiscExtension::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
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
 * Original code based on the CommonMark JS reference parser (http://bitly.com/commonmark-js)
9
 *  - (c) John MacFarlane
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 */
14
15
namespace League\CommonMark\Extension;
16
17
use League\CommonMark\Block\Parser\BlockParserInterface;
18
use League\CommonMark\Block\Renderer\BlockRendererInterface;
19
use League\CommonMark\DocumentProcessorInterface;
20
use League\CommonMark\Inline\Parser\InlineParserInterface;
21
use League\CommonMark\Inline\Processor\InlineProcessorInterface;
22
use League\CommonMark\Inline\Renderer\InlineRendererInterface;
23
24
class MiscExtension implements ExtensionInterface
25
{
26
    /**
27
     * @var BlockParserInterface[]
28
     */
29
    protected $blockParsers = [];
30
31
    /**
32
     * @var InlineParserInterface[]
33
     */
34
    protected $inlineParsers = [];
35
36
    /**
37
     * @var InlineProcessorInterface[]
38
     */
39
    protected $inlineProcessers = [];
40
41
    /**
42
     * @var DocumentProcessorInterface[]
43
     */
44
    protected $documentProcessors = [];
45
46
    /**
47
     * @var BlockRendererInterface[]
48
     */
49
    protected $blockRenderers = [];
50
51
    /**
52
     * @var InlineRendererInterface[]
53
     */
54
    protected $inlineRenderers = [];
55
56
    /**
57
     * Returns a list of block parsers to add to the existing list
58
     *
59
     * @return BlockParserInterface[]
60
     */
61 33
    public function getBlockParsers()
62
    {
63 33
        return $this->blockParsers;
64
    }
65
66
    /**
67
     * @param BlockParserInterface $blockParser
68
     *
69
     * @return $this
70
     */
71 6
    public function addBlockParser(BlockParserInterface $blockParser)
72
    {
73 6
        $this->blockParsers[] = $blockParser;
74
75 6
        return $this;
76
    }
77
78
    /**
79
     * Returns a list of inline parsers to add to the existing list
80
     *
81
     * @return InlineParserInterface[]
82
     */
83 33
    public function getInlineParsers()
84
    {
85 33
        return $this->inlineParsers;
86
    }
87
88
    /**
89
     * @param InlineParserInterface $inlineParser
90
     *
91
     * @return $this
92
     */
93 15
    public function addInlineParser(InlineParserInterface $inlineParser)
94
    {
95 15
        $this->inlineParsers[] = $inlineParser;
96 15
    }
97
98
    /**
99
     * Returns a list of inline processors to add to the existing list
100
     *
101
     * @return InlineProcessorInterface[]
102
     */
103 33
    public function getInlineProcessors()
104
    {
105 33
        return $this->inlineProcessers;
106
    }
107
108
    /**
109
     * @param InlineProcessorInterface $inlineProcessor
110
     *
111
     * @return $this
112
     */
113 6
    public function addInlineProcessor(InlineProcessorInterface $inlineProcessor)
114
    {
115 6
        $this->inlineProcessers[] = $inlineProcessor;
116
117 6
        return $this;
118
    }
119
120
    /**
121
     * @return DocumentProcessorInterface[]
122
     */
123 33
    public function getDocumentProcessors()
124
    {
125 33
        return $this->documentProcessors;
126
    }
127
128
    /**
129
     * @param DocumentProcessorInterface $documentProcessor
130
     *
131
     * @return $this
132
     */
133 9
    public function addDocumentProcessor(DocumentProcessorInterface $documentProcessor)
134
    {
135 9
        $this->documentProcessors[] = $documentProcessor;
136
137 9
        return $this;
138
    }
139
140
    /**
141
     * Returns a list of block renderers to add to the existing list
142
     *
143
     * The list keys are the block class names which the corresponding value (renderer) will handle.
144
     *
145
     * @return BlockRendererInterface[]
146
     */
147 33
    public function getBlockRenderers()
148
    {
149 33
        return $this->blockRenderers;
150
    }
151
152
    /**
153
     * @param string                 $blockClass
154
     * @param BlockRendererInterface $blockRenderer
155
     *
156
     * @return $this
157
     */
158 9
    public function addBlockRenderer($blockClass, BlockRendererInterface $blockRenderer)
159
    {
160 9
        if (class_exists('League\CommonMark\Block\Element\\' . $blockClass)) {
161 3
            $blockClass = 'League\CommonMark\Block\Element\\' . $blockClass;
162 3
        }
163
164 9
        $this->blockRenderers[$blockClass] = $blockRenderer;
165 9
    }
166
167
    /**
168
     * Returns a list of inline renderers to add to the existing list
169
     *
170
     * The list keys are the inline class names which the corresponding value (renderer) will handle.
171
     *
172
     * @return InlineRendererInterface[]
173
     */
174 33
    public function getInlineRenderers()
175
    {
176 33
        return $this->inlineRenderers;
177
    }
178
179
    /**
180
     * @param string                  $inlineClass
181
     * @param InlineRendererInterface $inlineRenderer
182
     *
183
     * @return $this
184
     */
185 9
    public function addInlineRenderer($inlineClass, InlineRendererInterface $inlineRenderer)
186
    {
187 9
        if (class_exists('League\CommonMark\Inline\Element\\' . $inlineClass)) {
188 3
            $inlineClass = 'League\CommonMark\Inline\Element\\' . $inlineClass;
189 3
        }
190
191 9
        $this->inlineRenderers[$inlineClass] = $inlineRenderer;
192
193 9
        return $this;
194
    }
195
}
196