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

Section::_getMap()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
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
10
/**
11
 * A project section.
12
 *
13
 * @see https://developers.asana.com/docs/asana-sections
14
 * @see https://developers.asana.com/docs/section
15
 *
16
 * @method string   getCreatedAt    ()
17
 * @method string   getName         ()
18
 * @method $this    setName         (string $name)
19
 * @method Project  getProject      ()
20
 */
21
class Section extends AbstractEntity {
22
23
    use CrudTrait;
24
25
    const TYPE = 'section';
26
27
    protected static $map = [
28
        'project' => Project::class
29
    ];
30
31
    final public function __toString (): string {
32
        return "sections/{$this->getGid()}";
33
    }
34
35
    final protected function _getDir (): string {
36
        return "{$this->getProject()}/sections";
37
    }
38
39
    /**
40
     * @return Task[]
41
     */
42
    public function getTasks () {
43
        return $this->loadAll(Task::class, 'tasks', ['section' => $this->getGid()]);
44
    }
45
46
    /**
47
     * Instantiates and returns a new task.
48
     *
49
     * @depends after-create
50
     * @return Task
51
     */
52
    public function newTask () {
53
        /** @var Task $task */
54
        $task = $this->factory(Task::class);
55
        return $task->addToProject($this);
56
    }
57
}