Passed
Push — master ( 1a00b5...984447 )
by y
03:02
created

Portfolio::_getDir()   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
9
/**
10
 * A portfolio.
11
 *
12
 * @see https://developers.asana.com/docs/asana-portfolios
13
 * @see https://developers.asana.com/docs/portfolio
14
 *
15
 * @method string           getColor        ()
16
 * @method $this            setColor        (string $color)
17
 * @method string           getCreatedAt    ()
18
 * @method User             getCreatedBy    ()
19
 * @method CustomField[]    getCustomFields ()
20
 * @method User[]           getMembers      ()
21
 * @method $this            setMembers      (User[] $members)
22
 * @method string           getName         ()
23
 * @method $this            setName         (string $name)
24
 * @method User             getOwner        ()
25
 * @method $this            setOwner        (User $owner)
26
 */
27
class Portfolio extends AbstractEntity {
28
29
    use CrudTrait;
30
    use WorkspaceTrait;
31
32
    const TYPE = 'portfolio';
33
34
    protected static $map = [
35
        'created_by' => User::class,
36
        'custom_fields' => [CustomField::class],
37
        'owner' => User::class,
38
        'members' => [User::class],
39
        'workspace' => Workspace::class
40
    ];
41
42
    final public function __toString (): string {
43
        return "portfolios/{$this->getGid()}";
44
    }
45
46
    final protected function _getDir (): string {
47
        return 'portfolios';
48
    }
49
50
    /**
51
     * @depends after-create
52
     * @param Project $item
53
     * @return $this
54
     */
55
    public function addItem (Project $item) {
56
        $this->api->post("{$this}/addItem", ['item' => $item->getGid()]);
57
        return $this;
58
    }
59
60
    /**
61
     * @param User $user
62
     * @return $this
63
     */
64
    public function addMember (User $user) {
65
        return $this->addMembers([$user]);
66
    }
67
68
    /**
69
     * @param User[] $users
70
     * @return $this
71
     */
72
    public function addMembers (array $users) {
73
        if ($this->hasGid()) {
74
            $this->api->post("{$this}/addMembers", ['members' => static::_getGids($users)]);
75
            $this->_merge('members', $users);
76
        }
77
        else {
78
            $this->_merge('members', $users, true);
79
        }
80
        return $this;
81
    }
82
83
    /**
84
     * @depends after-create
85
     * @return Project[]
86
     */
87
    public function getItems () {
88
        return $this->loadAll(Project::class, "{$this}/items");
89
    }
90
91
    /**
92
     * @depends after-create
93
     * @param Project $item
94
     * @return $this
95
     */
96
    public function removeItem (Project $item) {
97
        $this->api->post("{$this}/removeItem", ['item' => $item->getGid()]);
98
        return $this;
99
    }
100
101
    /**
102
     * @param User $user
103
     * @return $this
104
     */
105
    public function removeMember (User $user) {
106
        return $this->removeMembers([$user]);
107
    }
108
109
    /**
110
     * @param User[] $users
111
     * @return $this
112
     */
113
    public function removeMembers (array $users) {
114
        if ($this->hasGid()) {
115
            $this->api->post("{$this}/removeMembers", ['members' => static::_getGids($users)]);
116
        }
117
        $this->_remove('members', $users);
118
        return $this;
119
    }
120
}