Passed
Push — master ( e1698c...dba318 )
by y
02:23
created

CustomField::isEnum()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
rs 10
c 1
b 0
f 0
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\CustomValues;
9
use Helix\Asana\CustomField\EnumOption;
10
11
/**
12
 * A custom field.
13
 *
14
 * Because instance values differ depending on which entity they're attached to,
15
 * this class must never be mapped as an entity field.
16
 *
17
 * Instead, use {@see CustomValues} to map an array-object representation of an entity's custom field values.
18
 *
19
 * @see https://developers.asana.com/docs/#asana-custom-fields
20
 * @see https://developers.asana.com/docs/#tocS_CustomField
21
 *
22
 * @method string       getDescription      ()
23
 * @method $this        setDescription      (string $text)
24
 * @method EnumOption[] getEnumOptions      ()
25
 * @method string       getName             ()
26
 * @method $this        setName             (string $name)
27
 * @method int          getPrecision        ()
28
 * @method $this        setPrecision        (int $precision)
29
 * @method string       getResourceSubtype  ()
30
 * @method $this        setResourceSubtype  (string $type) @depends create-only
31
 */
32
class CustomField extends AbstractEntity {
33
34
    use CrudTrait;
35
    use WorkspaceTrait;
36
37
    const TYPE = 'custom_field';
38
    const TYPE_ENUM = 'enum';
39
    const TYPE_NUMBER = 'number';
40
    const TYPE_TEXT = 'text';
41
42
    final public function __toString (): string {
43
        return "custom_fields/{$this->getGid()}";
44
    }
45
46
    final protected function _getDir (): string {
47
        return 'custom_fields';
48
    }
49
50
    protected function _getMap (): array {
51
        return [
52
            'enum_options' => [EnumOption::class],
53
        ];
54
    }
55
56
    /**
57
     * @param string $name
58
     * @return EnumOption
59
     */
60
    public function addEnumOption (string $name) {
61
        /** @var EnumOption $option */
62
        $option = $this->factory(EnumOption::class);
63
        $option->setName($name);
1 ignored issue
show
Unused Code introduced by
The call to Helix\Asana\CustomField\EnumOption::setName() has too many arguments starting with $name. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

63
        $option->/** @scrutinizer ignore-call */ 
64
                 setName($name);

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.

Loading history...
64
        if ($this->hasGid()) {
65
            $option->create();
66
        }
67
        else {
68
            $this->diff['enum_options'] = true;
69
        }
70
        $this->data['enum_options'][] = $option;
71
        return $option;
72
    }
73
74
    /**
75
     * @return bool
76
     */
77
    public function hasNotificationsEnabled (): bool {
78
        return $this->_is('has_notifications_enabled');
79
    }
80
81
    /**
82
     * @return bool
83
     */
84
    public function isEnum (): bool {
85
        return $this->getResourceSubtype() === self::TYPE_ENUM;
86
    }
87
88
    /**
89
     * @return bool
90
     */
91
    public function isGlobalToWorkspace (): bool {
92
        return $this->_is('is_global_to_workspace');
93
    }
94
95
    /**
96
     * @return bool
97
     */
98
    final public function isText (): bool {
99
        return $this->getResourceSubtype() === self::TYPE_TEXT;
100
    }
101
102
    /**
103
     * @param bool $flag
104
     * @return $this
105
     */
106
    public function setGlobalToWorkspace (bool $flag) {
107
        return $this->_set('is_global_to_workspace', $flag);
108
    }
109
110
    /**
111
     * @param bool $flag
112
     * @return $this
113
     */
114
    public function setNotificationsEnabled (bool $flag) {
115
        return $this->_set('has_notifications_enabled', $flag);
116
    }
117
118
}