Passed
Push — main ( 16e3d2...2668c7 )
by Damien
07:42
created

Emoji::getText()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DH\Adf\Node\Inline;
6
7
use DH\Adf\Node\InlineNode;
8
9
/**
10
 * @see https://developer.atlassian.com/cloud/jira/platform/apis/document/nodes/emoji
11
 */
12
class Emoji extends InlineNode
13
{
14
    protected string $type = 'emoji';
15
    private string $shortName;
16
    private ?string $id;
17
    private ?string $text;
18
19
    public function __construct(string $shortName, ?string $id = null, ?string $text = null)
20
    {
21
        $this->shortName = $shortName;
22
        $this->id = $id;
23
        $this->text = $text;
24
    }
25
26
    public static function load(array $data): self
27
    {
28
        self::checkNodeData(static::class, $data, ['attrs']);
29
        self::checkRequiredKeys(['shortName'], $data['attrs']);
30
31
        return new self(trim($data['attrs']['shortName'], ' \t\n\r\0\x0B:'), $data['attrs']['id'] ?? null, $data['attrs']['text'] ?? null);
32
    }
33
34
    public function getShortName(): string
35
    {
36
        return $this->shortName;
37
    }
38
39
    public function getId(): ?string
40
    {
41
        return $this->id;
42
    }
43
44
    public function getText(): ?string
45
    {
46
        return $this->text;
47
    }
48
49
    protected function attrs(): array
50
    {
51
        $attrs = parent::attrs();
52
        $attrs['shortName'] = sprintf(':%s:', $this->shortName);
53
54
        if (null !== $this->id) {
55
            $attrs['id'] = $this->id;
56
        }
57
        if (null !== $this->text) {
58
            $attrs['text'] = $this->text;
59
        }
60
61
        return $attrs;
62
    }
63
}
64