1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace allejo\DaPulse\Objects; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class PulseColumnTextValue |
7
|
|
|
* |
8
|
|
|
* @package allejo\DaPulse\Objects |
9
|
|
|
* @since 0.2.1 |
10
|
|
|
*/ |
11
|
|
|
class PulseColumnTimelineValue extends PulseColumnValue |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* Get a timeline column's content |
15
|
|
|
* |
16
|
|
|
* @api |
17
|
|
|
* |
18
|
|
|
* @since 0.2.1 |
19
|
|
|
* |
20
|
|
|
* @return \DateTime[]|null The timeline's begin and end dates |
21
|
|
|
* |
22
|
|
|
* array( |
23
|
|
|
* 'from' => \DateTime |
24
|
|
|
* 'to' => \DateTime |
25
|
|
|
* ) |
26
|
|
|
*/ |
27
|
3 |
View Code Duplication |
public function getValue () |
|
|
|
|
28
|
|
|
{ |
29
|
3 |
|
if ($this->isNullValue()) |
30
|
|
|
{ |
31
|
1 |
|
return null; |
32
|
|
|
} |
33
|
|
|
|
34
|
2 |
|
if (!isset($this->column_value)) |
35
|
|
|
{ |
36
|
1 |
|
$this->setValue($this->jsonResponse); |
37
|
|
|
} |
38
|
|
|
|
39
|
2 |
|
return $this->column_value; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Update the values of a timeline column |
44
|
|
|
* |
45
|
|
|
* @api |
46
|
|
|
* |
47
|
|
|
* @param \DateTime $from |
48
|
|
|
* @param \DateTime $to |
49
|
|
|
* |
50
|
|
|
* @since 0.3.0 \InvalidArgumentException is now thrown |
51
|
|
|
* @since 0.2.1 |
52
|
|
|
* |
53
|
|
|
* @throws \InvalidArgumentException if $from or $to are not \DateTime instances |
54
|
|
|
*/ |
55
|
1 |
|
public function updateValue ($from, $to) |
|
|
|
|
56
|
|
|
{ |
57
|
1 |
|
if (!($from instanceof \DateTime) || !($to instanceof \DateTime)) |
58
|
|
|
{ |
59
|
|
|
throw new \InvalidArgumentException('$from and $to are expected to be \\DateTime instances'); |
60
|
|
|
} |
61
|
|
|
|
62
|
1 |
|
$url = sprintf("%s/%d/columns/%s/timeline.json", self::apiEndpoint(), $this->board_id, $this->column_id); |
63
|
|
|
$postParams = [ |
64
|
1 |
|
"pulse_id" => $this->pulse_id, |
65
|
1 |
|
"from" => $from->format('Y-m-d'), |
66
|
1 |
|
"to" => $to->format('Y-m-d') |
67
|
|
|
]; |
68
|
|
|
|
69
|
1 |
|
$result = self::sendPut($url, $postParams); |
70
|
1 |
|
$this->setValue($result); |
71
|
1 |
|
} |
72
|
|
|
|
73
|
2 |
|
protected function setValue ($response) |
74
|
|
|
{ |
75
|
2 |
|
$this->column_value = [ |
76
|
2 |
|
'from' => new \DateTime($response["value"]["from"]), |
77
|
2 |
|
'to' => new \DateTime($response["value"]["to"]) |
78
|
|
|
]; |
79
|
|
|
} |
80
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.