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

DescriptionV3::addDescriptionContent()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 10
nc 4
nop 3
dl 0
loc 20
rs 9.9332
c 0
b 0
f 0
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