Passed
Push — master ( 50a671...528684 )
by y
02:25
created

Status::_setData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
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\CreateTrait;
7
use Helix\Asana\Base\AbstractEntity\DeleteTrait;
8
use Helix\Asana\Project;
9
use Helix\Asana\User;
10
11
/**
12
 * A project status.
13
 *
14
 * @see https://developers.asana.com/docs/asana-project-statuses
15
 * @see https://developers.asana.com/docs/project-status
16
 *
17
 * @immutable Statuses may only be deleted after creation.
18
 *
19
 * @method string   getColor        ()
20
 * @method $this    setColor        (string $color) @depends create-only
21
 * @method string   getCreatedAt    ()
22
 * @method User     getCreatedBy    ()
23
 * @method string   getText         ()
24
 * @method $this    setText         (string $text)  @depends create-only
25
 * @method string   getTitle        ()
26
 */
27
class Status extends AbstractEntity {
28
29
    use CreateTrait;
30
    use DeleteTrait;
31
32
    const TYPE = 'project_status';
33
34
    const COLOR_GREEN = 'green';
35
    const COLOR_RED = 'red';
36
    const COLOR_YELLOW = 'yellow';
37
38
    protected static $map = [
39
        'created_by' => User::class
40
    ];
41
42
    /**
43
     * @var Project
44
     */
45
    protected $project;
46
47
    /**
48
     * Remote doesn't have a `project` property, so it's required here.
49
     *
50
     * @param Project $project
51
     * @param array $data
52
     */
53
    public function __construct (Project $project, array $data = []) {
54
        parent::__construct($project, $data);
55
        $this->project = $project;
56
    }
57
58
    final public function __toString (): string {
59
        return "project_statuses/{$this->getGid()}";
60
    }
61
62
    final protected function _getDir (): string {
63
        return "{$this->project}/project_statuses";
64
    }
65
66
    protected function _setData (array $data): void {
67
        // redundant, prefer created_by
68
        unset($data['author']);
69
        parent::_setData($data);
70
    }
71
72
    /**
73
     * @return Project
74
     */
75
    public function getProject () {
76
        return $this->project;
77
    }
78
}