|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Helix\Asana; |
|
4
|
|
|
|
|
5
|
|
|
use Helix\Asana\Base\AbstractEntity; |
|
6
|
|
|
use Helix\Asana\Base\AbstractEntity\CrudTrait; |
|
7
|
|
|
use Helix\Asana\Base\AbstractEntity\WorkspaceTrait; |
|
8
|
|
|
use Helix\Asana\CustomField\EnumOption; |
|
9
|
|
|
use Helix\Asana\Task\CustomValues; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* A custom field. |
|
13
|
|
|
* |
|
14
|
|
|
* Use {@see CustomValues} to map {@see Task} `custom_fields` as an array-object representation of values. |
|
15
|
|
|
* |
|
16
|
|
|
* @see https://developers.asana.com/docs/asana-custom-fields |
|
17
|
|
|
* @see https://developers.asana.com/docs/custom-field |
|
18
|
|
|
* |
|
19
|
|
|
* @method string getDescription () |
|
20
|
|
|
* @method $this setDescription (string $text) |
|
21
|
|
|
* @method EnumOption[] getEnumOptions () |
|
22
|
|
|
* @method string getName () |
|
23
|
|
|
* @method $this setName (string $name) |
|
24
|
|
|
* @method int getPrecision () |
|
25
|
|
|
* @method $this setPrecision (int $precision) |
|
26
|
|
|
* @method string getResourceSubtype () |
|
27
|
|
|
* @method $this setResourceSubtype (string $type) @depends create-only |
|
28
|
|
|
*/ |
|
29
|
|
|
class CustomField extends AbstractEntity { |
|
30
|
|
|
|
|
31
|
|
|
use CrudTrait; |
|
32
|
|
|
use WorkspaceTrait; |
|
33
|
|
|
|
|
34
|
|
|
const TYPE = 'custom_field'; |
|
35
|
|
|
const TYPE_ENUM = 'enum'; |
|
36
|
|
|
const TYPE_NUMBER = 'number'; |
|
37
|
|
|
const TYPE_TEXT = 'text'; |
|
38
|
|
|
|
|
39
|
|
|
protected static $map = [ |
|
40
|
|
|
'enum_options' => [EnumOption::class], |
|
41
|
|
|
]; |
|
42
|
|
|
|
|
43
|
|
|
final public function __toString (): string { |
|
44
|
|
|
return "custom_fields/{$this->getGid()}"; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
final protected function _getDir (): string { |
|
48
|
|
|
return 'custom_fields'; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @param string $name |
|
53
|
|
|
* @return EnumOption |
|
54
|
|
|
*/ |
|
55
|
|
|
public function addEnumOption (string $name) { |
|
56
|
|
|
/** @var EnumOption $option */ |
|
57
|
|
|
$option = $this->factory(EnumOption::class); |
|
58
|
|
|
$option->setName($name); |
|
|
|
|
|
|
59
|
|
|
if ($this->hasGid()) { |
|
60
|
|
|
$option->create(); |
|
61
|
|
|
} |
|
62
|
|
|
else { |
|
63
|
|
|
$this->diff['enum_options'] = true; |
|
64
|
|
|
} |
|
65
|
|
|
$this->data['enum_options'][] = $option; |
|
66
|
|
|
return $option; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @return bool |
|
71
|
|
|
*/ |
|
72
|
|
|
public function hasNotificationsEnabled (): bool { |
|
73
|
|
|
return $this->_is('has_notifications_enabled'); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @return bool |
|
78
|
|
|
*/ |
|
79
|
|
|
public function isEnum (): bool { |
|
80
|
|
|
return $this->getResourceSubtype() === self::TYPE_ENUM; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @return bool |
|
85
|
|
|
*/ |
|
86
|
|
|
public function isGlobalToWorkspace (): bool { |
|
87
|
|
|
return $this->_is('is_global_to_workspace'); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @return bool |
|
92
|
|
|
*/ |
|
93
|
|
|
final public function isText (): bool { |
|
94
|
|
|
return $this->getResourceSubtype() === self::TYPE_TEXT; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @param bool $flag |
|
99
|
|
|
* @return $this |
|
100
|
|
|
*/ |
|
101
|
|
|
public function setGlobalToWorkspace (bool $flag) { |
|
102
|
|
|
return $this->_set('is_global_to_workspace', $flag); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @param bool $flag |
|
107
|
|
|
* @return $this |
|
108
|
|
|
*/ |
|
109
|
|
|
public function setNotificationsEnabled (bool $flag) { |
|
110
|
|
|
return $this->_set('has_notifications_enabled', $flag); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
} |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.