Passed
Pull Request — latest (#598)
by Colin
16:46 queued 13:48
created

HeadingPermalinkExtension   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 12
c 1
b 0
f 0
dl 0
loc 20
ccs 14
cts 14
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configureSchema() 0 11 1
A register() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the league/commonmark package.
7
 *
8
 * (c) Colin O'Dell <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace League\CommonMark\Extension\HeadingPermalink;
15
16
use League\CommonMark\Configuration\ConfigurationBuilderInterface;
17
use League\CommonMark\Environment\EnvironmentBuilderInterface;
18
use League\CommonMark\Event\DocumentParsedEvent;
19
use League\CommonMark\Extension\ConfigurableExtensionInterface;
20
use League\CommonMark\Normalizer\SlugNormalizer;
21
use League\CommonMark\Normalizer\TextNormalizerInterface;
22
use Nette\Schema\Expect;
23
24
/**
25
 * Extension which automatically anchor links to heading elements
26
 */
27
final class HeadingPermalinkExtension implements ConfigurableExtensionInterface
28
{
29 87
    public function configureSchema(ConfigurationBuilderInterface $builder): void
30
    {
31 87
        $builder->addSchema('heading_permalink', Expect::structure([
32 87
            'min_heading_level' => Expect::int()->min(1)->max(6)->default(1),
33 87
            'max_heading_level' => Expect::int()->min(1)->max(6)->default(6),
34 87
            'slug_normalizer' => Expect::type(TextNormalizerInterface::class)->default(new SlugNormalizer()),
35 87
            'insert' => Expect::anyOf(HeadingPermalinkProcessor::INSERT_BEFORE, HeadingPermalinkProcessor::INSERT_AFTER)->default(HeadingPermalinkProcessor::INSERT_BEFORE),
36 87
            'id_prefix' => Expect::string()->default('user-content'),
37 87
            'html_class' => Expect::string()->default('heading-permalink'),
38 87
            'title' => Expect::string()->default('Permalink'),
39 87
            'symbol' => Expect::string()->default(HeadingPermalinkRenderer::DEFAULT_SYMBOL),
40
        ]));
41 87
    }
42
43 72
    public function register(EnvironmentBuilderInterface $environment): void
44
    {
45 72
        $environment->addEventListener(DocumentParsedEvent::class, new HeadingPermalinkProcessor(), -100);
46 72
        $environment->addRenderer(HeadingPermalink::class, new HeadingPermalinkRenderer());
47 72
    }
48
}
49