Completed
Push — develop ( f0afa6...187580 )
by Vladimir
03:00
created

PulseColumnTimelineValue   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 60
ccs 16
cts 16
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getValue() 0 4 1
A updateValue() 0 17 3
A setValue() 0 7 1
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
    public function getValue ()
28
    {
29 3
        return parent::getValue();
30
    }
31
32
    /**
33
     * Update the values of a timeline column
34
     *
35
     * @api
36
     *
37
     * @param \DateTime $from
38
     * @param \DateTime $to
39
     *
40
     * @since 0.3.0 \InvalidArgumentException is now thrown
41
     * @since 0.2.1
42
     *
43
     * @throws \InvalidArgumentException if $from or $to are not \DateTime instances
44
     */
45 1
    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...
46
    {
47 1
        if (!($from instanceof \DateTime) || !($to instanceof \DateTime))
48
        {
49
            throw new \InvalidArgumentException('$from and $to are expected to be \\DateTime instances');
50
        }
51
52 1
        $url        = sprintf("%s/%d/columns/%s/timeline.json", self::apiEndpoint(), $this->board_id, $this->column_id);
53
        $postParams = [
54 1
            "pulse_id" => $this->pulse_id,
55 1
            "from"     => $from->format('Y-m-d'),
56 1
            "to"       => $to->format('Y-m-d')
57
        ];
58
59 1
        $result = self::sendPut($url, $postParams);
60 1
        $this->setValue($result);
61 1
    }
62
63 2
    protected function setValue ($response)
64
    {
65 2
        $this->column_value = [
66 2
            'from' => new \DateTime($response["value"]["from"]),
67 2
            'to'   => new \DateTime($response["value"]["to"])
68
        ];
69
    }
70
}