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

TwemojiExtension   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
eloc 9
c 1
b 0
f 1
dl 0
loc 22
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 3 1
A configureSchema() 0 7 1
A __construct() 0 4 2
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