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

PulseColumnNumericValue::getValue()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 6

Duplication

Lines 14
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 14
loc 14
ccs 6
cts 6
cp 1
rs 9.4285
cc 3
eloc 6
nc 3
nop 0
crap 3
1
<?php
2
3
namespace allejo\DaPulse\Objects;
4
5
/**
6
 * Class PulseColumnTextValue
7
 *
8
 * @package allejo\DaPulse\Objects
9
 * @since   0.2.0
10
 */
11
class PulseColumnNumericValue extends PulseColumnValue
12
{
13
    /**
14
     * Get a numeric column's content
15
     *
16
     * @api
17
     *
18
     * @since  0.3.0 Docs correctly specify a numeric return type
19
     * @since  0.2.0
20
     *
21
     * @return int|double|null Null is returned if there is no value set for this column
22
     */
23 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...
24
    {
25 3
        if ($this->isNullValue())
26
        {
27 1
            return null;
28
        }
29
30 2
        if (!isset($this->column_value))
31
        {
32 1
            $this->setValue($this->jsonResponse);
33
        }
34
35 2
        return $this->column_value;
36
    }
37
38
    /**
39
     * Update the value of a numeric column
40
     *
41
     * @api
42
     *
43
     * @param int|double $number
44
     *
45
     * @since 0.3.0 \InvalidArgumentException is now thrown
46
     * @since 0.2.0
47
     *
48
     * @throws \InvalidArgumentException if $number is not a numeric value
49
     */
50 1 View Code Duplication
    public function updateValue ($number)
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...
51
    {
52 1
        if (!is_numeric($number))
53
        {
54
            throw new \InvalidArgumentException('$number is expected to be a numeric type');
55
        }
56
57 1
        $url        = sprintf("%s/%d/columns/%s/numeric.json", self::apiEndpoint(), $this->board_id, $this->column_id);
58
        $postParams = array(
59 1
            "pulse_id" => $this->pulse_id,
60 1
            "value"    => $number
61
        );
62
63 1
        $result = self::sendPut($url, $postParams);
64 1
        $this->setValue($result);
65 1
    }
66
67 2
    protected function setValue ($response)
68
    {
69 2
        $this->column_value = $response["value"];
70
    }
71
}