CommonMarkCoreExtension::register()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 52

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 42
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 52
ccs 42
cts 42
cp 1
rs 9.0472
c 0
b 0
f 0
cc 3
nc 4
nop 1
crap 3

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\Element as BlockElement;
18
use League\CommonMark\Block\Parser as BlockParser;
19
use League\CommonMark\Block\Renderer as BlockRenderer;
20
use League\CommonMark\ConfigurableEnvironmentInterface;
21
use League\CommonMark\Delimiter\Processor\EmphasisDelimiterProcessor;
22
use League\CommonMark\Inline\Element as InlineElement;
23
use League\CommonMark\Inline\Parser as InlineParser;
24
use League\CommonMark\Inline\Renderer as InlineRenderer;
25
26
final class CommonMarkCoreExtension implements ExtensionInterface
27
{
28 2064
    public function register(ConfigurableEnvironmentInterface $environment)
29
    {
30
        $environment
31 2064
            ->addBlockParser(new BlockParser\BlockQuoteParser(),      70)
32 2064
            ->addBlockParser(new BlockParser\ATXHeadingParser(),      60)
33 2064
            ->addBlockParser(new BlockParser\FencedCodeParser(),      50)
34 2064
            ->addBlockParser(new BlockParser\HtmlBlockParser(),       40)
35 2064
            ->addBlockParser(new BlockParser\SetExtHeadingParser(),   30)
36 2064
            ->addBlockParser(new BlockParser\ThematicBreakParser(),   20)
37 2064
            ->addBlockParser(new BlockParser\ListParser(),            10)
38 2064
            ->addBlockParser(new BlockParser\IndentedCodeParser(),  -100)
39 2064
            ->addBlockParser(new BlockParser\LazyParagraphParser(), -200)
40
41 2064
            ->addInlineParser(new InlineParser\NewlineParser(),     200)
42 2064
            ->addInlineParser(new InlineParser\BacktickParser(),    150)
43 2064
            ->addInlineParser(new InlineParser\EscapableParser(),    80)
44 2064
            ->addInlineParser(new InlineParser\EntityParser(),       70)
45 2064
            ->addInlineParser(new InlineParser\AutolinkParser(),     50)
46 2064
            ->addInlineParser(new InlineParser\HtmlInlineParser(),   40)
47 2064
            ->addInlineParser(new InlineParser\CloseBracketParser(), 30)
48 2064
            ->addInlineParser(new InlineParser\OpenBracketParser(),  20)
49 2064
            ->addInlineParser(new InlineParser\BangParser(),         10)
50
51 2064
            ->addBlockRenderer(BlockElement\BlockQuote::class,    new BlockRenderer\BlockQuoteRenderer(),    0)
52 2064
            ->addBlockRenderer(BlockElement\Document::class,      new BlockRenderer\DocumentRenderer(),      0)
53 2064
            ->addBlockRenderer(BlockElement\FencedCode::class,    new BlockRenderer\FencedCodeRenderer(),    0)
54 2064
            ->addBlockRenderer(BlockElement\Heading::class,       new BlockRenderer\HeadingRenderer(),       0)
55 2064
            ->addBlockRenderer(BlockElement\HtmlBlock::class,     new BlockRenderer\HtmlBlockRenderer(),     0)
56 2064
            ->addBlockRenderer(BlockElement\IndentedCode::class,  new BlockRenderer\IndentedCodeRenderer(),  0)
57 2064
            ->addBlockRenderer(BlockElement\ListBlock::class,     new BlockRenderer\ListBlockRenderer(),     0)
58 2064
            ->addBlockRenderer(BlockElement\ListItem::class,      new BlockRenderer\ListItemRenderer(),      0)
59 2064
            ->addBlockRenderer(BlockElement\Paragraph::class,     new BlockRenderer\ParagraphRenderer(),     0)
60 2064
            ->addBlockRenderer(BlockElement\ThematicBreak::class, new BlockRenderer\ThematicBreakRenderer(), 0)
61
62 2064
            ->addInlineRenderer(InlineElement\Code::class,       new InlineRenderer\CodeRenderer(),       0)
63 2064
            ->addInlineRenderer(InlineElement\Emphasis::class,   new InlineRenderer\EmphasisRenderer(),   0)
64 2064
            ->addInlineRenderer(InlineElement\HtmlInline::class, new InlineRenderer\HtmlInlineRenderer(), 0)
65 2064
            ->addInlineRenderer(InlineElement\Image::class,      new InlineRenderer\ImageRenderer(),      0)
66 2064
            ->addInlineRenderer(InlineElement\Link::class,       new InlineRenderer\LinkRenderer(),       0)
67 2064
            ->addInlineRenderer(InlineElement\Newline::class,    new InlineRenderer\NewlineRenderer(),    0)
68 2064
            ->addInlineRenderer(InlineElement\Strong::class,     new InlineRenderer\StrongRenderer(),     0)
69 2064
            ->addInlineRenderer(InlineElement\Text::class,       new InlineRenderer\TextRenderer(),       0)
70
        ;
71
72 2064
        if ($environment->getConfig('use_asterisk', true)) {
73 2064
            $environment->addDelimiterProcessor(new EmphasisDelimiterProcessor('*'));
74
        }
75
76 2064
        if ($environment->getConfig('use_underscore', true)) {
77 2064
            $environment->addDelimiterProcessor(new EmphasisDelimiterProcessor('_'));
78
        }
79 2064
    }
80
}
81