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

PulseColumnTextValue::updateValue()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 16
ccs 9
cts 9
cp 1
rs 9.2
cc 4
eloc 9
nc 2
nop 1
crap 4
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 PulseColumnTextValue extends PulseColumnValue
12
{
13
    /**
14
     * Get a text column's content
15
     *
16
     * @api
17
     *
18
     * @since  0.1.0
19
     *
20
     * @return string|null The column's content
21
     */
22 2
    public function getValue ()
23
    {
24 2
        return parent::getValue();
25
    }
26
27
    /**
28
     * Update the text of a text column
29
     *
30
     * @api
31
     *
32
     * @param string $text
33
     *
34
     * @since 0.3.0 \InvalidArgumentException is now thrown
35
     * @since 0.1.0
36
     *
37
     * @throws \InvalidArgumentException if $text does not have a string representation
38
     */
39 3
    public function updateValue ($text)
40
    {
41 3
        if (!is_scalar($text) || (is_object($text) && method_exists($text, '__toString')))
42
        {
43 2
            throw new \InvalidArgumentException('$text is expected to have a string representation');
44
        }
45
46 1
        $url        = sprintf("%s/%d/columns/%s/text.json", self::apiEndpoint(), $this->board_id, $this->column_id);
47
        $postParams = array(
48 1
            "pulse_id" => $this->pulse_id,
49 1
            "text"     => (string)$text
50
        );
51
52 1
        $result = self::sendPut($url, $postParams);
53 1
        $this->setValue($result);
54 1
    }
55
56 2
    protected function setValue ($response)
57
    {
58 2
        $this->column_value = $response["value"];
59
    }
60
}