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

IssueFieldV3::setEnvironment()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace JiraRestApi\Issue;
4
5
use JiraRestApi\ClassSerialize;
6
7
class IssueFieldV3 extends IssueField
8
{
9
    use ClassSerialize;
10
11
    /** @var \JiraRestApi\Issue\DescriptionV3|null */
12
    public $description;
13
14
    /** @var \JiraRestApi\Issue\DescriptionV3|null */
15
    public $environment;
16
17
    public function jsonSerialize()
18
    {
19
        $vars = array_filter(get_object_vars($this), function ($var) {
20
            return !is_null($var);
21
        });
22
23
        // if assignee property has empty value then remove it.
24
        // @see https://github.com/lesstif/php-jira-rest-client/issues/126
25
        // @see https://github.com/lesstif/php-jira-rest-client/issues/177
26
        if (!empty($this->assignee)) {
27
            // do nothing
28
            if ($this->assignee->isWantUnassigned() === true) {
29
            } elseif ($this->assignee->isEmpty()) {
30
                unset($vars['assignee']);
31
            }
32
        }
33
34
        // clear undefined json property
35
        unset($vars['customFields']);
36
37
        // repackaging custom field
38
        if (!empty($this->customFields)) {
39
            foreach ($this->customFields as $key => $value) {
40
                $vars[$key] = $value;
41
            }
42
        }
43
44
        return $vars;
45
    }
46
47
    /**
48
     * @param \JiraRestApi\Issue\DescriptionV3|null $description
49
     *
50
     * @return $this|IssueField
51
     */
52
    public function setDescription($description)
53
    {
54
        $this->description = $description;
55
56
        return $this;
57
    }
58
59
    /**
60
     * @param \JiraRestApi\Issue\DescriptionV3|null $description
61
     *
62
     * @return $this
63
     */
64
    public function addDescriptionParagraph($description)
65
    {
66
        if (empty($this->description)) {
67
            $this->description = new DescriptionV3();
68
        }
69
70
        $this->description->addDescriptionContent('paragraph', $description);
71
72
        return $this;
73
    }
74
75
    /**
76
     * @param int    $level       heading level
77
     * @param string $description
78
     *
79
     * @return $this
80
     */
81
    public function addDescriptionHeading($level, $description)
82
    {
83
        if (empty($this->description)) {
84
            $this->description = new DescriptionV3();
85
        }
86
87
        $this->description->addDescriptionContent('heading', $description, ['level' => $level]);
88
89
        return $this;
90
    }
91
92
    /**
93
     * @param \JiraRestApi\Issue\DescriptionV3|null $environment
94
     *
95
     * @return $this
96
     */
97
    public function setEnvironment($environment)
98
    {
99
        if (!empty($environment)) {
100
            $this->environment = $environment;
101
        }
102
103
        return $this;
104
    }
105
}
106