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

Story::_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\Task;
4
5
use Helix\Asana\Base\AbstractEntity;
6
use Helix\Asana\Base\AbstractEntity\CrudTrait;
7
use Helix\Asana\Task;
8
use Helix\Asana\User;
9
10
/**
11
 * A task story.
12
 *
13
 * @see https://developers.asana.com/docs/asana-stories
14
 * @see https://developers.asana.com/docs/story
15
 *
16
 * @method string       getCreatedAt        () RFC3339x
17
 * @method null|User    getCreatedBy        () This will be `null` if Asana produced the story.
18
 * @method bool         isLiked             ()
19
 * @method $this        setLiked            (string $liked)
20
 * @method Like[]       getLikes            ()
21
 * @method Like[]       selectLikes         (callable $filter) `fn( Like $like ): bool`
22
 * @method int          getNumLikes         ()
23
 * @method string       getResourceSubtype  () See the subtype constants.
24
 * @method string       getSource           () `web|api`
25
 * @method Task         getTarget           ()
26
 * @method string       getText             ()
27
 * @method $this        setText             (string $text) Comments only.
28
 */
29
class Story extends AbstractEntity {
30
31
    use CrudTrait;
32
33
    const TYPE = 'story';
34
    const TYPE_ASSIGNED = 'assigned';
35
    const TYPE_COMMENT_ADDED = 'comment_added';
36
    const TYPE_COMMENT_LIKED = 'comment_liked';
37
    const TYPE_DUE_DATE_CHANGED = 'due_date_changed';
38
    const TYPE_LIKED = 'liked';
39
    const TYPE_TAGGED = 'added_to_tag';
40
41
    protected static $map = [
42
        'created_by' => User::class,
43
        'likes' => [Like::class],
44
        'target' => Task::class
45
    ];
46
47
    final public function __toString (): string {
48
        return "stories/{$this->getGid()}";
49
    }
50
51
    final protected function _getDir (): string {
52
        return "{$this->getTarget()}/stories";
53
    }
54
55
    protected function _setData (array $data): void {
56
        // hearts are deprecated in favor of likes
57
        unset($data['hearted'], $data['hearts'], $data['num_hearts']);
58
        parent::_setData($data);
59
    }
60
61
    final public function isAssignment (): bool {
62
        return $this->getResourceSubtype() === self::TYPE_ASSIGNED;
63
    }
64
65
    final public function isComment (): bool {
66
        return $this->getResourceSubtype() === self::TYPE_COMMENT_ADDED;
67
    }
68
69
    final public function isDueDate (): bool {
70
        return $this->getResourceSubtype() === self::TYPE_DUE_DATE_CHANGED;
71
    }
72
73
    public function isEdited (): bool {
74
        return $this->_is('is_edited');
75
    }
76
77
    public function isFromApi (): bool {
78
        return $this->getSource() === 'api';
79
    }
80
81
    public function isFromWeb (): bool {
82
        return $this->getSource() === 'web';
83
    }
84
85
    public function isPinned (): bool {
86
        return $this->_is('is_pinned');
87
    }
88
89
    /**
90
     * @param bool $pinned
91
     * @return $this
92
     */
93
    public function setPinned (bool $pinned) {
94
        return $this->_set('is_pinned', $pinned);
95
    }
96
97
}