Passed
Push — main ( e16d46...16e3d2 )
by Damien
07:21
created

Emoji   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 18
dl 0
loc 35
c 0
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A attrs() 0 13 3
A load() 0 6 1
A __construct() 0 5 1
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
    protected function attrs(): array
35
    {
36
        $attrs = parent::attrs();
37
        $attrs['shortName'] = sprintf(':%s:', $this->shortName);
38
39
        if (null !== $this->id) {
40
            $attrs['id'] = $this->id;
41
        }
42
        if (null !== $this->text) {
43
            $attrs['text'] = $this->text;
44
        }
45
46
        return $attrs;
47
    }
48
}
49