PulseColumnPersonValue   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 1
dl 0
loc 67
c 0
b 0
f 0
ccs 20
cts 22
cp 0.9091
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getValue() 0 4 1
A updateValue() 0 13 1
A isNullValue() 0 10 6
A setValue() 0 10 2
1
<?php
2
3
/**
4
 * @copyright 2017 Vladimir Jimenez
5
 * @license   https://github.com/allejo/PhpPulse/blob/master/LICENSE.md MIT
6
 */
7
8
namespace allejo\DaPulse\Objects;
9
10
use allejo\DaPulse\Exceptions\ColumnNotFoundException;
11
use allejo\DaPulse\PulseUser;
12
13
/**
14
 * Class PulseColumnTextValue
15
 *
16
 * @package allejo\DaPulse\Objects
17
 * @since   0.1.0
18
 */
19
class PulseColumnPersonValue extends PulseColumnValue
20
{
21
    /**
22
     * Get the person assigned listed in the person column
23
     *
24
     * @api
25
     *
26
     * @since  0.4.0 ColumnNotFoundException is now thrown
27
     * @since  0.1.0
28
     *
29
     * @throws ColumnNotFoundException The specified column ID does not exist for the parent Pulse
30
     *
31
     * @return PulseUser|null Null is returned when no person is listed in this person column
32
     */
33 4
    public function getValue ()
34
    {
35 4
        return parent::getValue();
36
    }
37
38
    /**
39
     * Update the person in a person column
40
     *
41
     * @api
42
     *
43
     * @param int|PulseUser $user The new user that will be assigned to the person column
44
     *
45
     * @since 0.3.0 \InvalidArgumentException is now thrown
46
     * @since 0.1.0
47
     *
48
     * @throws \InvalidArgumentException if $user is not an integer, is not positive, or is not a PulseUser object
49
     */
50 7
    public function updateValue ($user)
51
    {
52 7
        $user       = PulseUser::_castToInt($user);
53 2
        $url        = sprintf("%s/%d/columns/%s/person.json", self::apiEndpoint(), $this->board_id, $this->column_id);
54
        $postParams = [
55 2
            "pulse_id" => $this->pulse_id,
56 2
            "user_id"  => $user
57
        ];
58
59 2
        $result = self::sendPut($url, $postParams);
60 2
        $this->jsonResponse = $result;
0 ignored issues
show
Documentation Bug introduced by
It seems like $result of type * is incompatible with the declared type array of property $jsonResponse.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
61 2
        $this->setValue($result);
62 2
    }
63
64 4
    protected function isNullValue ()
65
    {
66
        // Thank you very much, DaPulse. Changing the return type of an API endpoint clearly does not break any existing
67
        // code. Check to see if an invalid user is returned to be able to return null
68
69 4
        return parent::isNullValue() ||
70 3
               (is_array($this->jsonResponse) &&
71 3
                isset($this->jsonResponse['value']) && is_array($this->jsonResponse['value']) &&
72 4
                isset($this->jsonResponse['value']['id']) && $this->jsonResponse['value']['id'] === 0);
73
    }
74
75 3
    protected function setValue ($response)
76
    {
77 3
        if (!isset($response['value']['id']))
78
        {
79
            $this->column_value = null;
80
            return;
81
        }
82
83 3
        $this->column_value = new PulseUser($response["value"]["id"]);
84 3
    }
85
}
86