TwemojiExtension   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 41
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

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