EmojiConverter::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace League\Emoji;
6
7
use League\Emoji\Environment\Environment;
8
use League\Emoji\Environment\EnvironmentInterface;
9
use League\Emoji\Parser\EmojiParser;
10
use League\Emoji\Parser\EmojiParserInterface;
11
use League\Emoji\Renderer\DocumentRenderer;
12
use League\Emoji\Renderer\DocumentRendererInterface;
13
14
class EmojiConverter implements EmojiConverterInterface
15
{
16
    /** @var EnvironmentInterface */
17
    private $environment;
18
19
    /** @var EmojiParserInterface */
20
    private $parser;
21
22
    /** @var DocumentRendererInterface */
23
    private $renderer;
24
25 630
    public function __construct(EnvironmentInterface $environment, ?EmojiParserInterface $parser = null, ?DocumentRendererInterface $renderer = null)
26
    {
27 630
        $this->environment = $environment;
28 630
        $this->parser      = $parser ?? new EmojiParser($environment);
29 630
        $this->renderer    = $renderer ?? new DocumentRenderer($environment);
30 630
    }
31
32
    /**
33
     * @param array<string, mixed> $config
34
     */
35 81
    public static function create(array $config = []): EmojiConverterInterface
36
    {
37 81
        return new self(Environment::create($config));
38
    }
39
40
    /**
41
     * Converts all HTML entities, shortcodes or emoticons to emojis (unicode).
42
     *
43
     * @see EmojiConverterInterface::convert
44
     *
45
     * @throws \RuntimeException
46
     */
47 3
    public function __invoke(string $input): string
48
    {
49 3
        return $this->convert($input);
50
    }
51
52 231
    public function convert(string $input): string
53
    {
54 231
        $document = $this->parser->parse($input);
55
56 231
        return $this->renderer->renderDocument($document);
57
    }
58
59 531
    public function getEnvironment(): EnvironmentInterface
60
    {
61 531
        return $this->environment;
62
    }
63
64 3
    public function getParser(): EmojiParserInterface
65
    {
66 3
        return $this->parser;
67
    }
68
69 3
    public function getRenderer(): DocumentRendererInterface
70
    {
71 3
        return $this->renderer;
72
    }
73
}
74