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

EmojiConverter::convert()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 2
c 1
b 0
f 1
dl 0
loc 5
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace UnicornFail\Emoji;
6
7
use UnicornFail\Emoji\Environment\EnvironmentInterface;
8
use UnicornFail\Emoji\Output\RenderedContentInterface;
9
use UnicornFail\Emoji\Parser\EmojiParser;
10
use UnicornFail\Emoji\Parser\EmojiParserInterface;
11
use UnicornFail\Emoji\Renderer\DocumentRenderer;
12
use UnicornFail\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
    public function __construct(EnvironmentInterface $environment, ?EmojiParserInterface $parser = null, ?DocumentRendererInterface $renderer = null)
26
    {
27
        $this->environment = $environment;
28
        $this->parser      = $parser ?? new EmojiParser($environment);
29
        $this->renderer    = $renderer ?? new DocumentRenderer($environment);
30
    }
31
32
    /**
33
     * Converts all HTML entities, shortcodes or emoticons to emojis (unicode).
34
     *
35
     * @see EmojiConverterInterface::convert
36
     *
37
     * @throws \RuntimeException
38
     */
39
    public function __invoke(string $input): RenderedContentInterface
40
    {
41
        return $this->convert($input);
42
    }
43
44
    public function convert(string $input): RenderedContentInterface
45
    {
46
        $document = $this->parser->parse($input);
47
48
        return $this->renderer->renderDocument($document);
49
    }
50
51
    public function getEnvironment(): EnvironmentInterface
52
    {
53
        return $this->environment;
54
    }
55
}
56