Passed
Push — master ( 0658f3...f968a7 )
by y
02:18
created

TaskList::getPoolKeys()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 10
1
<?php
2
3
namespace Helix\Asana\User;
4
5
use Helix\Asana\Base\AbstractEntity;
6
use Helix\Asana\Base\AbstractEntity\ImmutableInterface;
7
use Helix\Asana\Task;
8
use Helix\Asana\User;
9
use Helix\Asana\Workspace;
10
use IteratorAggregate;
11
use Traversable;
12
13
/**
14
 * A user's task list in a given workspace.
15
 *
16
 * @see https://developers.asana.com/docs/asana-user-task-lists
17
 * @see https://developers.asana.com/docs/user-task-list
18
 *
19
 * @immutable User task lists are read-only through the API.
20
 *
21
 * @method string       getName         ()
22
 * @method User         getOwner        ()
23
 * @method Workspace    getWorkspace    ()
24
 */
25
class TaskList extends AbstractEntity implements ImmutableInterface, IteratorAggregate {
26
27
    const TYPE = 'user_task_list';
28
29
    protected const MAP = [
30
        'owner' => User::class,
31
        'workspace' => Workspace::class
32
    ];
33
34
    final public function __toString (): string {
35
        return "user_task_lists/{$this->getGid()}";
36
    }
37
38
    /**
39
     * @param array $filter
40
     * @return Traversable|Task[]
41
     */
42
    public function getIterator (array $filter = []) {
43
        return $this->api->loadEach($this, Task::class, "{$this}/tasks");
44
    }
45
46
    public function getPoolKeys () {
47
        $keys = parent::getPoolKeys();
48
49
        /** @see User::getTaskList() */
50
        $keys[] = "{$this->getOwner()}/user_task_list?workspace={$this->getWorkspace()->getGid()}";
51
52
        return $keys;
53
    }
54
55
    /**
56
     * All of the user's tasks.
57
     *
58
     * @see https://developers.asana.com/docs/get-tasks-from-a-user-task-list
59
     *
60
     * @param array $filter
61
     * @return Task[]
62
     */
63
    public function getTasks (array $filter = []) {
64
        return iterator_to_array($this->getIterator($filter));
65
    }
66
67
    /**
68
     * @param callable $filter `fn( Task $task ): bool`
69
     * @param array $apiFilter Given to the API to reduce network load.
70
     * @return Task[]
71
     */
72
    public function selectTasks (callable $filter, array $apiFilter) {
73
        return $this->_select($this->getIterator($apiFilter), $filter);
74
    }
75
}