Passed
Branch master (1a758e)
by y
01:58
created

Status::delete()   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\CreateTrait;
7
use Helix\Asana\Base\AbstractEntity\DeleteTrait;
8
use Helix\Asana\Base\AbstractEntity\ImmutableInterface;
9
use Helix\Asana\Project;
10
use Helix\Asana\User;
11
12
/**
13
 * A project status.
14
 *
15
 * @immutable Statuses can only be created and deleted.
16
 *
17
 * @see https://developers.asana.com/docs/asana-project-statuses
18
 * @see https://developers.asana.com/docs/project-status
19
 *
20
 * @see Project::newStatus()
21
 *
22
 * @method $this    setColor        (string $color)     @depends create-only, `green|red|yellow`
23
 * @method $this    setText         (string $text)      @depends create-only
24
 * @method $this    setTitle        (string $title)     @depends create-only
25
 *
26
 * @method string   getColor        () `green|red|yellow`
27
 * @method string   getCreatedAt    () RFC3339x
28
 * @method User     getCreatedBy    ()
29
 * @method string   getText         ()
30
 * @method string   getTitle        ()
31
 */
32
class Status extends AbstractEntity implements ImmutableInterface {
33
34
    use CreateTrait {
35
        create as private _create;
36
    }
37
    use DeleteTrait {
38
        delete as private _delete;
39
    }
40
41
    const DIR = 'project_statuses';
42
    const TYPE = 'project_status';
43
44
    const COLOR_GREEN = 'green';
45
    const COLOR_RED = 'red';
46
    const COLOR_YELLOW = 'yellow';
47
48
    protected const MAP = [
49
        'created_by' => User::class
50
    ];
51
52
    /**
53
     * @var Project
54
     */
55
    protected $parent;
56
57
    /**
58
     * @param Project $project
59
     * @param array $data
60
     */
61
    public function __construct (Project $project, array $data = []) {
62
        $this->parent = $project;
63
        parent::__construct($project, $data);
64
    }
65
66
    protected function _setData (array $data): void {
67
        // redundant, prefer created_by
68
        unset($data['author']);
69
70
        // statuses are immutable and asana doesn't accept or return this field despite being documented.
71
        unset($data['modified_at']);
72
73
        parent::_setData($data);
74
    }
75
76
    /**
77
     * @return $this
78
     */
79
    public function create () {
80
        $this->_create();
81
        $this->parent->_reload('current_status');
82
        return $this;
83
    }
84
85
    public function delete (): void {
86
        $this->_delete();
87
        $this->parent->_reload('current_status');
88
    }
89
90
    /**
91
     * @return Project
92
     */
93
    public function getProject () {
94
        return $this->parent;
95
    }
96
}