TaskList::getPoolKeys()   A
last analyzed

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
 * @immutable User task lists cannot be altered via the API.
17
 *
18
 * @see https://developers.asana.com/docs/asana-user-task-lists
19
 * @see https://developers.asana.com/docs/user-task-list
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 DIR = 'user_task_lists';
28
    const TYPE = 'user_task_list';
29
30
    protected const MAP = [
31
        'owner' => User::class,
32
        'workspace' => Workspace::class
33
    ];
34
35
    /**
36
     * @param array $filter
37
     * @return Traversable|Task[]
38
     */
39
    public function getIterator (array $filter = Task::GET_INCOMPLETE) {
40
        return $this->api->loadEach($this, Task::class, "{$this}/tasks", $filter);
41
    }
42
43
    public function getPoolKeys () {
44
        $keys = parent::getPoolKeys();
45
46
        /** @see User::getTaskList() */
47
        $keys[] = "{$this->getOwner()}/user_task_list?workspace={$this->getWorkspace()->getGid()}";
48
49
        return $keys;
50
    }
51
52
    /**
53
     * All of the user's tasks.
54
     *
55
     * @see https://developers.asana.com/docs/get-tasks-from-a-user-task-list
56
     *
57
     * @param array $filter
58
     * @return Task[]
59
     */
60
    public function getTasks (array $filter = Task::GET_INCOMPLETE) {
61
        return iterator_to_array($this->getIterator($filter));
62
    }
63
64
    /**
65
     * @param callable $filter `fn( Task $task ): bool`
66
     * @param array $apiFilter Given to the API to reduce network load.
67
     * @return Task[]
68
     */
69
    public function selectTasks (callable $filter, array $apiFilter = Task::GET_INCOMPLETE) {
70
        return $this->_select($this->getIterator($apiFilter), $filter);
71
    }
72
}