Completed
Push — toc-changes ( e65cac...16e29a )
by Colin
02:29
created

TableOfContentsExtension   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 4
dl 0
loc 13
c 0
b 0
f 0
ccs 6
cts 6
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 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
 * 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\Extension\TableOfContents;
13
14
use League\CommonMark\Environment\ConfigurableEnvironmentInterface;
15
use League\CommonMark\Event\DocumentParsedEvent;
16
use League\CommonMark\Extension\ExtensionInterface;
17
use League\CommonMark\Extension\TableOfContents\Node\TableOfContentsPlaceholder;
18
19
final class TableOfContentsExtension implements ExtensionInterface
20
{
21 36
    public function register(ConfigurableEnvironmentInterface $environment): void
22
    {
23 36
        $environment->addEventListener(DocumentParsedEvent::class, [new TableOfContentsBuilder(), 'onDocumentParsed'], -150);
24
25 36
        if ($environment->getConfig('table_of_contents/position') === TableOfContentsBuilder::POSITION_PLACEHOLDER) {
26 3
            $environment->addBlockStartParser(TableOfContentsPlaceholderParser::blockStartParser(), 200);
27
            // If a placeholder cannot be replaced with a TOC element this renderer will ensure the parser won't error out
28 3
            $environment->addRenderer(TableOfContentsPlaceholder::class, new TableOfContentsPlaceholderRenderer());
29
        }
30 36
    }
31
}
32