Completed
Push — latest ( 7e49ae...5ac9c7 )
by Colin
20s queued 12s
created

DefaultAttributesExtension   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configureSchema() 0 9 1
A register() 0 3 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\DefaultAttributes;
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 Nette\Schema\Expect;
21
22
final class DefaultAttributesExtension implements ConfigurableExtensionInterface
23
{
24 12
    public function configureSchema(ConfigurationBuilderInterface $builder): void
25
    {
26 12
        $builder->addSchema('default_attributes', Expect::arrayOf(
27 12
            Expect::arrayOf(
28 12
                Expect::type('string|string[]|bool|callable'), // attribute value(s)
29 12
                'string' // attribute name
30
            ),
31 12
            'string' // node FQCN
32 12
        )->default([]));
33 12
    }
34
35 12
    public function register(EnvironmentBuilderInterface $environment): void
36
    {
37 12
        $environment->addEventListener(DocumentParsedEvent::class, [new ApplyDefaultAttributesProcessor(), 'onDocumentParsed']);
38 12
    }
39
}
40