Passed
Push — master ( 2428ce...06a092 )
by y
02:04
created

Section::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Helix\Asana\Project;
4
5
use Helix\Asana\Base\AbstractEntity;
6
use Helix\Asana\Base\AbstractEntity\CrudTrait;
7
use Helix\Asana\Project;
8
use Helix\Asana\Task;
9
use IteratorAggregate;
10
use Traversable;
11
12
/**
13
 * A project section.
14
 *
15
 * @see https://developers.asana.com/docs/asana-sections
16
 * @see https://developers.asana.com/docs/section
17
 *
18
 * @method string   getCreatedAt    () RFC3339x
19
 * @method string   getName         ()
20
 * @method Project  getProject      ()
21
 *
22
 * @method $this    setName         (string $name)
23
 */
24
class Section extends AbstractEntity implements IteratorAggregate {
25
26
    use CrudTrait;
27
28
    const DIR = 'sections';
29
    const TYPE = 'section';
30
31
    protected const MAP = [
32
        'project' => Project::class
33
    ];
34
35
    /**
36
     * @var Project
37
     */
38
    protected $parent;
39
40
    public function __construct ($caller, array $data = []) {
41
        parent::__construct($caller, $data);
42
        $this->parent = $this->getProject();
43
    }
44
45
    /**
46
     * @param array $filter
47
     * @return Traversable|Task[]
48
     */
49
    public function getIterator (array $filter = Task::GET_INCOMPLETE) {
50
        $filter['section'] = $this->getGid();
51
        return $this->api->loadEach($this, Task::class, 'tasks', $filter);
52
    }
53
54
    /**
55
     * @param array $filter
56
     * @return Task[]
57
     */
58
    public function getTasks (array $filter = Task::GET_INCOMPLETE) {
59
        return iterator_to_array($this->getIterator($filter));
60
    }
61
62
    /**
63
     * Factory.
64
     *
65
     * @depends after-create
66
     * @return Task
67
     */
68
    public function newTask () {
69
        /** @var Task $task */
70
        $task = $this->api->factory($this, Task::class);
71
        return $task->addToProject($this);
72
    }
73
}