Passed
Push — master ( ff2040...6f6996 )
by KwangSeob
02:18
created

DescriptionV3   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonSerialize() 0 3 1
A addDescriptionContent() 0 20 3
1
<?php
2
3
namespace JiraRestApi\Issue;
4
5
/**
6
 * REST API V3 Issue description field.
7
 *
8
 * Class DescriptionV3
9
 */
10
class DescriptionV3 implements \JsonSerializable
11
{
12
    /* @var string */
13
    public $self;
14
15
    /* @var string */
16
    public $type = 'doc';
17
18
    /* @var integer */
19
    public $version = 1;
20
21
    /** @var \JiraRestApi\Issue\ContentField[]|null */
22
    public $content;
23
24
    public function jsonSerialize()
25
    {
26
        return array_filter(get_object_vars($this));
27
    }
28
29
    public function addDescriptionContent($type, $text, $attrs = [])
30
    {
31
        $cf = new ContentField();
32
33
        $cf->type = $type;
34
35
        if (!empty($attrs)) {
36
            $cf->attrs = $attrs;
37
        }
38
39
        $cf->content[] = [
40
            'type' => 'text',
41
            'text' => $text,
42
        ];
43
44
        if (empty($this->content)) {
45
            $this->content = [];
46
        }
47
48
        $this->content[] = $cf;
49
    }
50
}
51