MiscExtension   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 176
Duplicated Lines 0 %

Coupling/Cohesion

Components 6
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 14
lcom 6
cbo 0
dl 0
loc 176
ccs 36
cts 36
cp 1
rs 10
c 0
b 0
f 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
A getBlockParsers() 0 4 1
A addBlockParser() 0 6 1
A getInlineParsers() 0 4 1
A addInlineParser() 0 6 1
A getInlineProcessors() 0 4 1
A addInlineProcessor() 0 6 1
A getDocumentProcessors() 0 4 1
A addDocumentProcessor() 0 6 1
A getBlockRenderers() 0 4 1
A addBlockRenderer() 0 10 2
A getInlineRenderers() 0 4 1
A addInlineRenderer() 0 10 2
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 (https://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 36
    public function getBlockParsers()
62
    {
63 36
        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 36
    public function getInlineParsers()
84
    {
85 36
        return $this->inlineParsers;
86
    }
87
88
    /**
89
     * @param InlineParserInterface $inlineParser
90
     *
91
     * @return $this
92
     */
93 18
    public function addInlineParser(InlineParserInterface $inlineParser)
94
    {
95 18
        $this->inlineParsers[] = $inlineParser;
96
97 18
        return $this;
98
    }
99
100
    /**
101
     * Returns a list of inline processors to add to the existing list
102
     *
103
     * @return InlineProcessorInterface[]
104
     */
105 36
    public function getInlineProcessors()
106
    {
107 36
        return $this->inlineProcessers;
108
    }
109
110
    /**
111
     * @param InlineProcessorInterface $inlineProcessor
112
     *
113
     * @return $this
114
     */
115 6
    public function addInlineProcessor(InlineProcessorInterface $inlineProcessor)
116
    {
117 6
        $this->inlineProcessers[] = $inlineProcessor;
118
119 6
        return $this;
120
    }
121
122
    /**
123
     * @return DocumentProcessorInterface[]
124
     */
125 36
    public function getDocumentProcessors()
126
    {
127 36
        return $this->documentProcessors;
128
    }
129
130
    /**
131
     * @param DocumentProcessorInterface $documentProcessor
132
     *
133
     * @return $this
134
     */
135 9
    public function addDocumentProcessor(DocumentProcessorInterface $documentProcessor)
136
    {
137 9
        $this->documentProcessors[] = $documentProcessor;
138
139 9
        return $this;
140
    }
141
142
    /**
143
     * Returns a list of block renderers to add to the existing list
144
     *
145
     * The list keys are the block class names which the corresponding value (renderer) will handle.
146
     *
147
     * @return BlockRendererInterface[]
148
     */
149 36
    public function getBlockRenderers()
150
    {
151 36
        return $this->blockRenderers;
152
    }
153
154
    /**
155
     * @param string                 $blockClass
156
     * @param BlockRendererInterface $blockRenderer
157
     *
158
     * @return $this
159
     */
160 9
    public function addBlockRenderer($blockClass, BlockRendererInterface $blockRenderer)
161
    {
162 9
        if (class_exists('League\CommonMark\Block\Element\\' . $blockClass)) {
163 3
            $blockClass = 'League\CommonMark\Block\Element\\' . $blockClass;
164 1
        }
165
166 9
        $this->blockRenderers[$blockClass] = $blockRenderer;
167
168 9
        return $this;
169
    }
170
171
    /**
172
     * Returns a list of inline renderers to add to the existing list
173
     *
174
     * The list keys are the inline class names which the corresponding value (renderer) will handle.
175
     *
176
     * @return InlineRendererInterface[]
177
     */
178 36
    public function getInlineRenderers()
179
    {
180 36
        return $this->inlineRenderers;
181
    }
182
183
    /**
184
     * @param string                  $inlineClass
185
     * @param InlineRendererInterface $inlineRenderer
186
     *
187
     * @return $this
188
     */
189 9
    public function addInlineRenderer($inlineClass, InlineRendererInterface $inlineRenderer)
190
    {
191 9
        if (class_exists('League\CommonMark\Inline\Element\\' . $inlineClass)) {
192 3
            $inlineClass = 'League\CommonMark\Inline\Element\\' . $inlineClass;
193 1
        }
194
195 9
        $this->inlineRenderers[$inlineClass] = $inlineRenderer;
196
197 9
        return $this;
198
    }
199
}
200