Completed
Push — master ( 95cc27...d32772 )
by Vladimir
05:08 queued 03:05
created

PulseColumnTimelineValue::setValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
crap 1
1
<?php
2
3
/**
4
 * @copyright 2017 Vladimir Jimenez
5
 * @license   https://github.com/allejo/PhpPulse/blob/master/LICENSE.md MIT
6
 */
7
8
namespace allejo\DaPulse\Objects;
9
10
/**
11
 * Class PulseColumnTextValue
12
 *
13
 * @package allejo\DaPulse\Objects
14
 * @since   0.2.1
15
 */
16
class PulseColumnTimelineValue extends PulseColumnValue
17
{
18
    /**
19
     * Get a timeline column's content
20
     *
21
     * @api
22
     *
23
     * @since  0.2.1
24
     *
25
     * @return \DateTime[]|null The timeline's begin and end dates
26
     *
27
     *     array(
28
     *       'from' => \DateTime
29
     *       'to'   => \DateTime
30
     *     )
31
     */
32 3
    public function getValue ()
33
    {
34 3
        return parent::getValue();
35
    }
36
37
    /**
38
     * Update the values of a timeline column
39
     *
40
     * @api
41
     *
42
     * @param \DateTime $from
43
     * @param \DateTime $to
44
     *
45
     * @since 0.3.0 \InvalidArgumentException is now thrown
46
     * @since 0.2.1
47
     *
48
     * @throws \InvalidArgumentException if $from or $to are not \DateTime instances
49
     */
50 3
    public function updateValue ($from, $to)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $to. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
51
    {
52 3
        if (!($from instanceof \DateTime) || !($to instanceof \DateTime))
53
        {
54 2
            throw new \InvalidArgumentException('$from and $to are expected to be \\DateTime instances');
55
        }
56
57 1
        $url        = sprintf("%s/%d/columns/%s/timeline.json", self::apiEndpoint(), $this->board_id, $this->column_id);
58
        $postParams = [
59 1
            "pulse_id" => $this->pulse_id,
60 1
            "from"     => $from->format('Y-m-d'),
61 1
            "to"       => $to->format('Y-m-d')
62
        ];
63
64 1
        $result = self::sendPut($url, $postParams);
65 1
        $this->setValue($result);
66 1
    }
67
68 2
    protected function setValue ($response)
69
    {
70 2
        $this->column_value = [
71 2
            'from' => new \DateTime($response["value"]["from"]),
72 2
            'to'   => new \DateTime($response["value"]["to"])
73
        ];
74
    }
75
}