Passed
Push — master ( b66c10...181037 )
by y
02:15
created

Team   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 12
c 4
b 0
f 0
dl 0
loc 55
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 2 1
A addUser() 0 3 1
A removeUser() 0 3 1
A getUrl() 0 2 1
A getUsers() 0 2 1
A getProjects() 0 2 1
1
<?php
2
3
namespace Helix\Asana;
4
5
use Helix\Asana\Base\AbstractEntity;
6
7
/**
8
 * A team.
9
 *
10
 * @see https://developers.asana.com/docs/asana-teams
11
 * @see https://developers.asana.com/docs/team
12
 *
13
 * @immutable Teams cannot be altered via the API.
14
 *
15
 * @method string       getDescription      ()
16
 * @method string       getHtmlDescription  ()
17
 * @method string       getName             ()
18
 * @method Workspace    getOrganization     ()
19
 */
20
class Team extends AbstractEntity {
21
22
    const TYPE = 'team';
23
24
    protected static $map = [
25
        'organization' => Workspace::class
26
    ];
27
28
    final public function __toString (): string {
29
        return "teams/{$this->getGid()}";
30
    }
31
32
    /**
33
     * @param User $user
34
     * @return $this
35
     */
36
    public function addUser (User $user) {
37
        $this->api->post("{$this}/addUser", ['user' => $user->getGid()]);
38
        return $this;
39
    }
40
41
    /**
42
     * The team's projects.
43
     *
44
     * @see https://developers.asana.com/docs/get-a-teams-projects
45
     *
46
     * @param array $filter
47
     * @return Project[]
48
     */
49
    public function getProjects (array $filter = ['archived' => false]) {
50
        return $this->loadAll(Project::class, "{$this}/projects", $filter);
51
    }
52
53
    public function getUrl (): string {
54
        return "https://app.asana.com/0/{$this->getGid()}/overview";
55
    }
56
57
    /**
58
     * The team's users.
59
     *
60
     * @see https://developers.asana.com/docs/get-users-in-a-team
61
     *
62
     * @return User[]
63
     */
64
    public function getUsers () {
65
        return $this->loadAll(User::class, "{$this}/users");
66
    }
67
68
    /**
69
     * @param User $user
70
     * @return $this
71
     */
72
    public function removeUser (User $user) {
73
        $this->api->post("{$this}/removeUser", ['user' => $user->getGid()]);
74
        return $this;
75
    }
76
}