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

Text   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 18
dl 0
loc 37
c 1
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonSerialize() 0 6 1
A load() 0 15 3
A __construct() 0 6 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DH\Adf\Node\Inline;
6
7
use DH\Adf\Node\InlineNode;
8
use DH\Adf\Node\MarkNode;
9
use DH\Adf\Node\Node;
10
11
/**
12
 * @see https://developer.atlassian.com/cloud/jira/platform/apis/document/nodes/text
13
 */
14
class Text extends InlineNode
15
{
16
    protected string $type = 'text';
17
    private string $text;
18
19
    public function __construct(string $text, MarkNode ...$marks)
20
    {
21
        $this->text = $text;
22
23
        foreach ($marks as $mark) {
24
            $this->addMark($mark);
25
        }
26
    }
27
28
    public function jsonSerialize(): array
29
    {
30
        $result = parent::jsonSerialize();
31
        $result['text'] = $this->text;
32
33
        return $result;
34
    }
35
36
    public static function load(array $data): self
37
    {
38
        self::checkNodeData(static::class, $data, ['text']);
39
40
        $args = [];
41
        if (\array_key_exists('marks', $data)) {
42
            foreach ($data['marks'] as $nodeData) {
43
                $class = Node::NODE_MAPPING[$nodeData['type']];
44
                $node = $class::load($nodeData);
45
                \assert($node instanceof MarkNode);
46
                $args[] = $node;
47
            }
48
        }
49
50
        return new self($data['text'], ...$args);
51
    }
52
}
53