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

Attachment::_getMap()   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 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Helix\Asana\Task;
4
5
use Helix\Asana\Base\AbstractEntity;
6
use Helix\Asana\Base\AbstractEntity\DeleteTrait;
7
use Helix\Asana\Task;
8
9
/**
10
 * A file attachment.
11
 *
12
 * @see https://developers.asana.com/docs/asana-attachments
13
 * @see https://developers.asana.com/docs/attachment
14
 *
15
 * @immutable Attachments may only be deleted after creation.
16
 *
17
 * @method string   getCreatedAt    ()
18
 * @method string   getDownloadUrl  ()
19
 * @method string   getHost         ()
20
 * @method string   getName         ()
21
 * @method Task     getParent       ()
22
 * @method string   getPermanentUrl () Short, human-friendly.
23
 * @method string   getViewUrl      ()
24
 */
25
class Attachment extends AbstractEntity {
26
27
    use DeleteTrait;
28
29
    const TYPE = 'attachment';
30
31
    protected static $map = [
32
        'parent' => Task::class
33
    ];
34
35
    final public function __toString (): string {
36
        return "attachments/{$this->getGid()}";
37
    }
38
39
    /**
40
     * Creates the attachment by uploading a file.
41
     *
42
     * @param string $file
43
     * @return $this
44
     */
45
    public function upload (string $file) {
46
        // api returns compact version. reload.
47
        $remote = $this->api->upload("{$this->getParent()}/attachments", $file);
48
        $this->data['gid'] = $remote['gid'];
49
        $this->reload();
50
        return $this;
51
    }
52
}