Passed
Push — master ( b4f796...2ef625 )
by y
01:41
created

Section   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 37
rs 10
c 1
b 0
f 0
eloc 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A _getMap() 0 3 1
A _getDir() 0 2 1
A getTasks() 0 2 1
A __toString() 0 2 1
A newTask() 0 4 1
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/#tocS_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
    final public function __toString (): string {
28
        return "sections/{$this->getGid()}";
29
    }
30
31
    final protected function _getDir (): string {
32
        return "{$this->getProject()}/sections";
33
    }
34
35
    protected function _getMap (): array {
36
        return [
37
            'project' => Project::class
38
        ];
39
    }
40
41
    /**
42
     * @return Task[]
43
     */
44
    public function getTasks () {
45
        return $this->loadAll(Task::class, 'tasks', ['section' => $this->getGid()]);
46
    }
47
48
    /**
49
     * Instantiates and returns a new task.
50
     *
51
     * @depends after-create
52
     * @return Task
53
     */
54
    public function newTask () {
55
        /** @var Task $task */
56
        $task = $this->factory(Task::class);
57
        return $task->addToProject($this);
58
    }
59
}