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

TableHeader::load()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 23
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 23
c 1
b 0
f 0
rs 9.8333
cc 3
nc 2
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DH\Adf\Node\Child;
6
7
use DH\Adf\Node\BlockNode;
8
use DH\Adf\Node\Node;
9
use JsonSerializable;
10
11
/**
12
 * @see https://developer.atlassian.com/cloud/jira/platform/apis/document/nodes/table_header
13
 */
14
class TableHeader extends TableCell implements JsonSerializable
15
{
16
    protected string $type = 'tableHeader';
17
18
    public static function load(array $data, ?BlockNode $parent = null): self
19
    {
20
        self::checkNodeData(static::class, $data);
21
22
        $node = new self(
23
            $data['attrs']['background'] ?? null,
24
            $data['attrs']['colspan'] ?? null,
25
            $data['attrs']['rowspan'] ?? null,
26
            $data['attrs']['colwidth'] ?? null,
27
            $parent
28
        );
29
30
        // set content if defined
31
        if (\array_key_exists('content', $data)) {
32
            foreach ($data['content'] as $nodeData) {
33
                $class = Node::NODE_MAPPING[$nodeData['type']];
34
                $child = $class::load($nodeData, $node);
35
36
                $node->append($child);
37
            }
38
        }
39
40
        return $node;
41
    }
42
}
43