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

PulseColumnTextValue   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 50
ccs 14
cts 14
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getValue() 0 4 1
A updateValue() 0 16 4
A setValue() 0 4 1
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
}