1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace allejo\DaPulse\Objects; |
4
|
|
|
|
5
|
|
|
use allejo\DaPulse\PulseUser; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class PulseColumnTextValue |
9
|
|
|
* |
10
|
|
|
* @package allejo\DaPulse\Objects |
11
|
|
|
* @since 0.1.0 |
12
|
|
|
*/ |
13
|
|
|
class PulseColumnPersonValue extends PulseColumnValue |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* Get the person assigned listed in the person column |
17
|
|
|
* |
18
|
|
|
* **Warning** This function may return a null value so ensure the returned value is not null before calling any |
19
|
|
|
* functions that belong to a PulseUser object. |
20
|
|
|
* |
21
|
|
|
* @api |
22
|
|
|
* |
23
|
|
|
* @since 0.1.0 |
24
|
|
|
* |
25
|
|
|
* @return PulseUser|null Null is returned when no person is listed in this person column |
26
|
|
|
*/ |
27
|
|
View Code Duplication |
public function getValue () |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
if ($this->isNullValue()) |
30
|
|
|
{ |
31
|
|
|
return null; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
if (!isset($this->column_value)) |
35
|
|
|
{ |
36
|
|
|
$this->column_value = new PulseUser($this->jsonResponse["value"]["id"]); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
return $this->column_value; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Update the person in a person column |
44
|
|
|
* |
45
|
|
|
* **Warning** Currently, there is no way of removing a person from a column; only replacing them. |
46
|
|
|
* |
47
|
|
|
* @api |
48
|
|
|
* |
49
|
|
|
* @param int|PulseUser $user The new user that will be assigned to the person column |
50
|
|
|
* |
51
|
|
|
* @since 0.1.0 |
52
|
|
|
*/ |
53
|
|
|
public function updateValue ($user) |
54
|
|
|
{ |
55
|
|
|
$user = ($user instanceof PulseUser) ? $user->getId() : $user; |
56
|
|
|
$url = sprintf("%s/%d/columns/%s/person.json", self::apiEndpoint(), $this->board_id, $this->column_id); |
57
|
|
|
$postParams = array( |
58
|
|
|
"pulse_id" => $this->pulse_id, |
59
|
|
|
"user_id" => $user |
60
|
|
|
); |
61
|
|
|
|
62
|
|
|
self::sendPut($url, $postParams); |
63
|
|
|
|
64
|
|
|
$this->column_value = new PulseUser($user); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* {@inheritdoc} |
69
|
|
|
*/ |
70
|
|
|
protected function isNullValue () |
71
|
|
|
{ |
72
|
|
|
// Thank you very much, DaPulse. Changing the return type of an API endpoint clearly does not break any existing |
73
|
|
|
// code. Check to see if an invalid user is returned to be able to return null |
74
|
|
|
|
75
|
|
|
$isNullUser = array_key_exists('value', $this->jsonResponse) && |
76
|
|
|
array_key_exists('id', $this->jsonResponse['value']) && |
77
|
|
|
$this->jsonResponse['value']['id'] === 0; |
78
|
|
|
|
79
|
|
|
return (parent::isNullValue() || $isNullUser); |
80
|
|
|
} |
81
|
|
|
} |
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.