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

InlineCard   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 16
dl 0
loc 36
c 0
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 3
A load() 0 5 1
A attrs() 0 12 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DH\Adf\Node\Inline;
6
7
use DH\Adf\Node\BlockNode;
8
use DH\Adf\Node\InlineNode;
9
use InvalidArgumentException;
10
11
/**
12
 * @see https://developer.atlassian.com/cloud/jira/platform/apis/document/nodes/inlineCard
13
 */
14
class InlineCard extends InlineNode
15
{
16
    protected string $type = 'inlineCard';
17
    private ?string $data;
18
    private ?string $url;
19
20
    public function __construct(?string $url = null, ?string $data = null)
21
    {
22
        if (null === $data && null === $url) {
23
            throw new InvalidArgumentException('Either data or url must be set.');
24
        }
25
26
        // TODO: ensure data, if provided, is valid jsonld
27
        $this->data = $data;
28
        $this->url = $url;
29
    }
30
31
    public static function load(array $data, ?BlockNode $parent = null): self
32
    {
33
        self::checkNodeData(static::class, $data);
34
35
        return new self($data['attrs']['url'] ?? null, $data['attrs']['data'] ?? null);
36
    }
37
38
    protected function attrs(): array
39
    {
40
        $attrs = parent::attrs();
41
42
        if (null !== $this->data) {
43
            $attrs['data'] = $this->data;
44
        }
45
        if (null !== $this->url) {
46
            $attrs['url'] = $this->url;
47
        }
48
49
        return $attrs;
50
    }
51
}
52