Passed
Push — renovate/phpunit-phpunit-12.x ( 0cf44b...73c751 )
by
unknown
10:49 queued 07:50
created

AttributesExtension::configureSchema()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the league/commonmark package.
5
 *
6
 * (c) Colin O'Dell <[email protected]>
7
 * (c) 2015 Martin Hasoň <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
declare(strict_types=1);
14
15
namespace League\CommonMark\Extension\Attributes;
16
17
use League\CommonMark\Environment\EnvironmentBuilderInterface;
18
use League\CommonMark\Event\DocumentParsedEvent;
19
use League\CommonMark\Extension\Attributes\Event\AttributesListener;
20
use League\CommonMark\Extension\Attributes\Parser\AttributesBlockStartParser;
21
use League\CommonMark\Extension\Attributes\Parser\AttributesInlineParser;
22
use League\CommonMark\Extension\ConfigurableExtensionInterface;
23
use League\Config\ConfigurationBuilderInterface;
24
use Nette\Schema\Expect;
25
26
final class AttributesExtension implements ConfigurableExtensionInterface
27
{
28 22
    public function configureSchema(ConfigurationBuilderInterface $builder): void
29
    {
30 22
        $builder->addSchema('attributes', Expect::structure([
31 22
            'allow' => Expect::arrayOf('string')->default([]),
32 22
        ]));
33
    }
34
35 22
    public function register(EnvironmentBuilderInterface $environment): void
36
    {
37 22
        $allowList        = $environment->getConfiguration()->get('attributes.allow');
38 22
        $allowUnsafeLinks = $environment->getConfiguration()->get('allow_unsafe_links');
39
40 22
        $environment->addBlockStartParser(new AttributesBlockStartParser());
41 22
        $environment->addInlineParser(new AttributesInlineParser());
42 22
        $environment->addEventListener(DocumentParsedEvent::class, [new AttributesListener($allowList, $allowUnsafeLinks), 'processDocument']);
43
    }
44
}
45