Completed
Push — master ( a34372...4a8cdc )
by KwangSeob
01:46
created

Worklog::setVisibility()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace JiraRestApi\Issue;
4
5
use JiraRestApi\ClassSerialize;
6
use JiraRestApi\JiraException;
7
8
/**
9
 * Class Worklog.
10
 */
11
class Worklog
12
{
13
    use ClassSerialize;
14
    use VisibilityTrait;
15
16
    /**
17
     * @var int id of worklog
18
     */
19
    public $id;
20
21
    /**
22
     * @var string api link of worklog
23
     */
24
    public $self;
25
26
    /**
27
     * @var array details about author
28
     */
29
    public $author;
30
31
    /**
32
     * @var array
33
     */
34
    public $updateAuthor;
35
36
    /**
37
     * @var string
38
     */
39
    public $updated;
40
41
    /**
42
     * @var string
43
     */
44
    public $timeSpent;
45
46
    /**
47
     * @var string
48
     */
49
    public $comment;
50
51
    /**
52
     * @var string
53
     */
54
    public $started;
55
56
    /**
57
     * @var int
58
     */
59
    public $timeSpentSeconds;
60
61
    /**
62
     * @var \JiraRestApi\Issue\Visibility
63
     */
64
    public $visibility;
65
66
    /**
67
     * Function to serialize obj vars.
68
     *
69
     * @return array
70
     */
71
    public function jsonSerialize()
72
    {
73
        return array_filter(get_object_vars($this));
74
    }
75
76
    /**
77
     * Function to set comments.
78
     *
79
     * @param string $comment
80
     *
81
     * @return Worklog
82
     */
83
    public function setComment($comment)
84
    {
85
        $this->comment = $comment;
86
87
        return $this;
88
    }
89
90
    /**
91
     * Function to set start time of worklog.
92
     *
93
     * @param mixed $started started time value(\DateTime|string)  e.g. -  new DateTime("2016-03-17 11:15:34") or "2016-03-17 11:15:34"
94
     *
95
     * @throws JiraException
96
     *
97
     * @return Worklog
98
     */
99
    public function setStarted($started)
100
    {
101
        if (is_string($started)) {
102
            $dt = new \DateTime($started);
103
        } elseif ($started instanceof \DateTime) {
104
            $dt = $started;
105
        } else {
106
            throw new JiraException('field only accept date string or DateTime class.'.get_class($started));
107
        }
108
109
        // workround micro second
110
        $this->started = $dt->format("Y-m-d\TH:i:s").'.000'.$dt->format('O');
111
112
        return $this;
113
    }
114
115
    /**
116
     * Function to set start time of worklog.
117
     *
118
     * @param \DateTime $started e.g. -  new DateTime("2014-04-05 16:00:00")
119
     *
120
     * @return Worklog
121
     */
122
    public function setStartedDateTime($started)
123
    {
124
        // workround micro second
125
        $this->started = $started->format("Y-m-d\TH:i:s").'.000'.$started->format('O');
126
127
        return $this;
128
    }
129
130
    /**
131
     * Function to set worklog time in string.
132
     *
133
     * @param string $timeSpent
134
     *
135
     * @return Worklog
136
     */
137
    public function setTimeSpent($timeSpent)
138
    {
139
        $this->timeSpent = $timeSpent;
140
141
        return $this;
142
    }
143
144
    /**
145
     * Function to set worklog time in seconds.
146
     *
147
     * @param int $timeSpentSeconds
148
     *
149
     * @return Worklog
150
     */
151
    public function setTimeSpentSeconds($timeSpentSeconds)
152
    {
153
        $this->timeSpentSeconds = $timeSpentSeconds;
154
155
        return $this;
156
    }
157
}
158