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

Status::getStyle()   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
use InvalidArgumentException;
9
10
/**
11
 * @see https://developer.atlassian.com/cloud/jira/platform/apis/document/nodes/text
12
 */
13
class Status extends InlineNode
14
{
15
    public const COLOR_NEUTRAL = 'neutral';
16
    public const COLOR_GREEN = 'green';
17
    public const COLOR_PURPLE = 'purple';
18
    public const COLOR_BLUE = 'blue';
19
    public const COLOR_RED = 'red';
20
    public const COLOR_YELLOW = 'yellow';
21
22
    protected string $type = 'status';
23
    private string $text;
24
    private string $color;
25
    private ?string $localId;
26
    private ?string $style;
27
28
    public function __construct(string $text, string $color, ?string $localId = null, ?string $style = null)
29
    {
30
        if (!\in_array($color, [
31
            self::COLOR_NEUTRAL,
32
            self::COLOR_GREEN,
33
            self::COLOR_PURPLE,
34
            self::COLOR_BLUE,
35
            self::COLOR_RED,
36
            self::COLOR_YELLOW,
37
        ], true)) {
38
            throw new InvalidArgumentException('Invalid color');
39
        }
40
41
        $this->text = $text;
42
        $this->color = $color;
43
        $this->localId = $localId;
44
        $this->style = $style;
45
    }
46
47
    public static function load(array $data): self
48
    {
49
        self::checkNodeData(static::class, $data, ['attrs']);
50
        self::checkRequiredKeys(['text', 'color'], $data['attrs']);
51
52
        return new self(
53
            $data['attrs']['text'],
54
            $data['attrs']['color'],
55
            $data['attrs']['localId'] ?? null,
56
            $data['attrs']['style'] ?? null
57
        );
58
    }
59
60
    public function getText(): string
61
    {
62
        return $this->text;
63
    }
64
65
    public function getColor(): string
66
    {
67
        return $this->color;
68
    }
69
70
    public function getLocalId(): ?string
71
    {
72
        return $this->localId;
73
    }
74
75
    public function getStyle(): ?string
76
    {
77
        return $this->style;
78
    }
79
80
    protected function attrs(): array
81
    {
82
        $attrs = parent::attrs();
83
        $attrs['text'] = $this->text;
84
        $attrs['color'] = $this->color;
85
86
        if (null !== $this->localId) {
87
            $attrs['localId'] = $this->localId;
88
        }
89
        if (null !== $this->style) {
90
            $attrs['style'] = $this->style;
91
        }
92
93
        return $attrs;
94
    }
95
}
96