Completed
Push — master ( f665df...a43901 )
by KwangSeob
02:15
created

Reporter   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 28
dl 0
loc 81
rs 10
c 0
b 0
f 0
wmc 14

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isEmpty() 0 7 3
B jsonSerialize() 0 19 8
A isWantUnassigned() 0 6 2
A setWantUnassigned() 0 4 1
1
<?php
2
3
namespace JiraRestApi\Issue;
4
5
use JiraRestApi\ClassSerialize;
6
7
class Reporter implements \JsonSerializable
8
{
9
    use ClassSerialize;
10
11
    /** @var string */
12
    public $self;
13
14
    /** @var string */
15
    public $name;
16
17
    /** @var string */
18
    public $emailAddress;
19
20
    /** @var array|null */
21
    public $avatarUrls;
22
23
    /** @var string */
24
    public $displayName;
25
26
    /** @var string */
27
    public $active;
28
29
    // want assignee to unassigned
30
    private $wantUnassigned = false;
31
32
    public function jsonSerialize()
33
    {
34
        $vars = (get_object_vars($this));
35
36
        foreach ($vars as $key => $value) {
37
            if ($key === 'name' && ($this->isWantUnassigned() === true)) {
38
                continue;
39
            } elseif ($key === 'wantUnassigned') {
40
                unset($vars[$key]);
41
            } elseif (is_null($value) || $value === '') {
42
                unset($vars[$key]);
43
            }
44
        }
45
46
        if (empty($vars)) {
47
            return;
48
        }
49
50
        return $vars;
51
    }
52
53
    /**
54
     * determine class has value for effective json serialize.
55
     *
56
     * @see https://github.com/lesstif/php-jira-rest-client/issues/126
57
     *
58
     * @return bool
59
     */
60
    public function isEmpty()
61
    {
62
        if (empty($this->name) && empty($this->self)) {
63
            return true;
64
        }
65
66
        return false;
67
    }
68
69
    /**
70
     * @return boolean
71
     */
72
    public function isWantUnassigned()
73
    {
74
        if ($this->wantUnassigned)
75
            return true;
76
77
        return false;
78
    }
79
80
    /**
81
     * @param $param boolean
82
     *
83
     */
84
    public function setWantUnassigned($param)
85
    {
86
        $this->wantUnassigned = $param;
87
        $this->name = null;
88
    }
89
}
90