PulseColumnTimelineValue::updateValue()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 18
c 0
b 0
f 0
ccs 11
cts 11
cp 1
rs 9.6666
cc 3
nc 2
nop 2
crap 3
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
use allejo\DaPulse\Exceptions\ColumnNotFoundException;
11
12
/**
13
 * Class PulseColumnTextValue
14
 *
15
 * @package allejo\DaPulse\Objects
16
 * @since   0.2.1
17
 */
18
class PulseColumnTimelineValue extends PulseColumnValue
19
{
20
    /**
21
     * Get a timeline column's content
22
     *
23
     * @api
24
     *
25
     * @since  0.4.0 ColumnNotFoundException is now thrown
26
     * @since  0.2.1
27
     *
28
     * @throws ColumnNotFoundException The specified column ID does not exist for the parent Pulse
29
     *
30
     * @return \DateTime[]|null The timeline's begin and end dates
31
     *
32
     *     array(
33
     *       'from' => \DateTime
34
     *       'to'   => \DateTime
35
     *     )
36
     */
37 3
    public function getValue ()
38
    {
39 3
        return parent::getValue();
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 3
    public function updateValue ($from, $to)
56
    {
57 3
        if (!($from instanceof \DateTime) || !($to instanceof \DateTime))
58
        {
59 2
            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->jsonResponse = $result;
0 ignored issues
show
Documentation Bug introduced by
It seems like $result of type * is incompatible with the declared type array of property $jsonResponse.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
71 1
        $this->setValue($result);
72 1
    }
73
74 2
    protected function setValue ($response)
75
    {
76 2
        $this->column_value = [
77 2
            'from' => new \DateTime($response["value"]["from"]),
78 2
            'to'   => new \DateTime($response["value"]["to"])
79
        ];
80
    }
81
}