Test Setup Failed
Pull Request — latest (#3)
by Mark
34:22
created

TwemojiExtension::configureSchema()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 5
c 1
b 0
f 1
dl 0
loc 7
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace UnicornFail\Emoji\Extension\Twemoji;
6
7
use League\Configuration\ConfigurationBuilderInterface;
8
use Nette\Schema\Expect;
9
use UnicornFail\Emoji\Environment\EnvironmentBuilderInterface;
10
use UnicornFail\Emoji\Event\DocumentParsedEvent;
11
use UnicornFail\Emoji\Exception\ExtensionRequiredLibraryException;
12
use UnicornFail\Emoji\Extension\ConfigurableExtensionInterface;
13
14
final class TwemojiExtension implements ConfigurableExtensionInterface
15
{
16
    public function __construct()
17
    {
18
        if (! \class_exists('\Astrotomic\Twemoji\Twemoji')) {
19
            throw new ExtensionRequiredLibraryException('astrotomic/php-twemoji', $this);
20
        }
21
    }
22
23
    public function configureSchema(ConfigurationBuilderInterface $builder): void
24
    {
25
        $builder->addSchema('twemoji', Expect::structure([
26
            'base'    => Expect::string('https://twemoji.maxcdn.com/v/latest'),
27
            'classes' => Expect::arrayOf('string')->default(['twemoji']),
28
            'size'    => Expect::int()->nullable(),
29
            'type'    => Expect::anyOf('png', 'svg')->default('svg'),
30
        ]));
31
    }
32
33
    public function register(EnvironmentBuilderInterface $environment): void
34
    {
35
        $environment->addEventListener(DocumentParsedEvent::class, new TwemojiProcessor());
36
    }
37
}
38