Completed
Push — develop ( a05ff5...d1fb89 )
by Vladimir
03:27
created

PulseColumnDateValue::updateValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 16
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 16
loc 16
ccs 8
cts 8
cp 1
rs 9.4285
cc 2
eloc 9
nc 2
nop 1
crap 2
1
<?php
2
3
namespace allejo\DaPulse\Objects;
4
5
/**
6
 * Class PulseColumnTextValue
7
 *
8
 * @package allejo\DaPulse\Objects
9
 * @since   0.1.0
10
 */
11
class PulseColumnDateValue extends PulseColumnValue
12
{
13
    /**
14
     * Get the date listed in the date column
15
     *
16
     * @api
17
     *
18
     * @since  0.1.0
19
     *
20
     * @return \DateTime|null Null is returned if there is no value set for this column
21
     */
22 3 View Code Duplication
    public function getValue ()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
23
    {
24 3
        if ($this->isNullValue())
25
        {
26 2
            return null;
27
        }
28
29 2
        if (!isset($this->column_value))
30
        {
31 1
            $this->setValue($this->jsonResponse);
32
        }
33
34 2
        return $this->column_value;
35
    }
36
37
    /**
38
     * Update the date of the date column.
39
     *
40
     * The specific time of the DateTime object will be ignored.
41
     *
42
     * @api
43
     *
44
     * @param \DateTime $dateTime The new date
45
     *
46
     * @since 0.3.0 \InvalidArgumentException is now thrown
47
     * @since 0.1.0
48
     *
49
     * @throws \InvalidArgumentException if $dateTime is not a \DateTime
50
     */
51 1 View Code Duplication
    public function updateValue ($dateTime)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
52
    {
53 1
        if (!($dateTime instanceof \DateTime))
54
        {
55
            throw new \InvalidArgumentException('$dateTime is expected to be of type \\DateTime');
56
        }
57
58 1
        $url        = sprintf("%s/%d/columns/%s/date.json", self::apiEndpoint(), $this->board_id, $this->column_id);
59
        $postParams = array(
60 1
            "pulse_id" => $this->pulse_id,
61 1
            "date_str" => date_format($dateTime, "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
        // Another DaPulse API inconsistency. The data returned from a PUT request has the date in an array instead of
71
        // of a string.
72 2
        if (is_array($response['value']) && isset($response['value']['date']))
73
        {
74 1
            $this->column_value = new \DateTime($response['value']['date']);
75 1
            return;
76
        }
77
78 1
        $this->column_value = new \DateTime($response['value']);
79
    }
80
}