Test Setup Failed
Pull Request — latest (#3)
by Mark
33:50
created

TwemojiExtension   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
eloc 15
c 1
b 0
f 1
dl 0
loc 34
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 3 1
A configureSchema() 0 11 1
A configureConversionTypes() 0 8 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace UnicornFail\Emoji\Extension\Twemoji;
6
7
use Dflydev\DotAccessData\Data;
8
use League\Configuration\ConfigurationBuilderInterface;
9
use Nette\Schema\Expect;
10
use UnicornFail\Emoji\Environment\EnvironmentBuilderInterface;
11
use UnicornFail\Emoji\Event\DocumentParsedEvent;
12
use UnicornFail\Emoji\Extension\ConfigurableExtensionInterface;
13
use UnicornFail\Emoji\Extension\ConfigureConversionTypesInterface;
14
15
final class TwemojiExtension implements ConfigurableExtensionInterface, ConfigureConversionTypesInterface
16
{
17
    public const CONVERSION_TYPE = TwemojiProcessor::CONVERSION_TYPE;
18
19
    /**
20
     * {@inheritDoc}
21
     */
22
    public function configureConversionTypes(string &$default, array &$conversionTypes, Data $rawConfig): void
23
    {
24
        // Set the default conversion type to Twemoji.
25
        if (! $rawConfig->has('twemoji.defaultConversionType') || $rawConfig->get('twemoji.defaultConversionType') === true) {
26
            $default = TwemojiProcessor::CONVERSION_TYPE;
27
        }
28
29
        $conversionTypes[] = TwemojiProcessor::CONVERSION_TYPE;
30
    }
31
32
    public function configureSchema(ConfigurationBuilderInterface $builder, Data $rawConfig): void
33
    {
34
        $builder->addSchema('twemoji', Expect::structure([
35
            'defaultConversionType' => Expect::bool(true),
36
            'classes'               => Expect::arrayOf('string')->default(['twemoji']),
37
            'classPrefix'           => Expect::string('twemoji-')->nullable(),
38
            'icon'                  => Expect::bool(false)->nullable(),
39
            'inlineSvg'             => Expect::bool(true),
40
            'size'                  => Expect::int()->nullable(),
41
            'type'                  => Expect::anyOf('png', 'svg')->default('svg'),
42
            'urlBase'               => Expect::string('https://twemoji.maxcdn.com/v/latest'),
43
        ]));
44
    }
45
46
    public function register(EnvironmentBuilderInterface $environment): void
47
    {
48
        $environment->addEventListener(DocumentParsedEvent::class, new TwemojiProcessor());
49
    }
50
}
51