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

EmojiImage::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 5
c 1
b 0
f 1
dl 0
loc 10
rs 10
cc 2
nc 2
nop 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace UnicornFail\Emoji\Node\Inline;
6
7
use UnicornFail\Emoji\Dataset\Emoji;
8
use UnicornFail\Emoji\Util\HtmlElement;
9
10
final class EmojiImage extends AbstractEmoji
11
{
12
    /** @var HtmlElement */
13
    private $element;
14
15
    public function __construct(string $value, Emoji $emoji, string $url, ?string $alt = null)
16
    {
17
        parent::__construct($value, $emoji);
18
19
        $this->element = new HtmlElement('img', [], '', true);
20
21
        $this->element->setAttribute('src', $url);
22
23
        if ($alt !== null) {
24
            $this->element->setAttribute('alt', $alt);
25
        }
26
    }
27
28
    public function addClass(string ...$classes): void
29
    {
30
        $this->element->addClass(...$classes);
31
    }
32
33
    public function getElement(): HtmlElement
34
    {
35
        return $this->element;
36
    }
37
38
    public function getLiteral(): string
39
    {
40
        return (string) $this->element;
41
    }
42
43
    public function getUrl(): string
44
    {
45
        return (string) $this->element->getAttribute('src');
46
    }
47
48
    public function setAttribute(string $name, string $value): void
49
    {
50
        $this->data->set('attributes.' . $name, $value);
51
    }
52
}
53