Story   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 29
c 2
b 0
f 0
dl 0
loc 108
rs 10
wmc 13

13 Methods

Rating   Name   Duplication   Size   Complexity  
A isEdited() 0 2 1
A isLikedComment() 0 2 1
A isLikedTask() 0 2 1
A isPinned() 0 2 1
A isTag() 0 2 1
A isFromApi() 0 2 1
A setPinned() 0 2 1
A isAssignment() 0 2 1
A isDueDate() 0 2 1
A isFromWeb() 0 2 1
A __construct() 0 3 1
A _setData() 0 5 1
A isComment() 0 2 1
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
 * @see Task::newComment()
17
 *
18
 * @method $this        setText             (string $text) @depends create-only, comments only
19
 *
20
 * @method string       getCreatedAt        () RFC3339x
21
 * @method null|User    getCreatedBy        () This will be `null` if Asana produced the story.
22
 * @method bool         isLiked             () Whether the story is liked by the API user.
23
 * @method Like[]       getLikes            () Other people's likes.
24
 * @method int          getNumLikes         ()
25
 * @method string       getResourceSubtype  () See the subtype constants.
26
 * @method string       getSource           () `web|api`
27
 * @method Task         getTarget           ()
28
 * @method string       getText             ()
29
 *
30
 * @method $this        setLiked            (bool $liked)
31
 *
32
 * @method Like[]       selectLikes         (callable $filter) `fn( Like $like ): bool`
33
 */
34
class Story extends AbstractEntity {
35
36
    use CrudTrait;
37
38
    const DIR = 'stories';
39
    const TYPE = 'story';
40
41
    const TYPE_ASSIGNED = 'assigned';
42
    const TYPE_COMMENT_ADDED = 'comment_added';
43
    const TYPE_COMMENT_LIKED = 'comment_liked';
44
    const TYPE_DUE_DATE_CHANGED = 'due_date_changed';
45
    const TYPE_LIKED = 'liked';
46
    const TYPE_TAGGED = 'added_to_tag';
47
48
    protected const MAP = [
49
        'created_by' => User::class,
50
        'likes' => [Like::class],
51
        'target' => Task::class
52
    ];
53
54
    public function __construct ($caller, array $data = []) {
55
        parent::__construct($caller, $data);
56
        $this->parent = $this->getTarget();
57
    }
58
59
    protected function _setData (array $data): void {
60
        // hearts were deprecated for likes
61
        unset($data['hearted'], $data['hearts'], $data['num_hearts']);
62
63
        parent::_setData($data);
64
    }
65
66
    /**
67
     * @return bool
68
     */
69
    final public function isAssignment (): bool {
70
        return $this->getResourceSubtype() === self::TYPE_ASSIGNED;
71
    }
72
73
    /**
74
     * @return bool
75
     */
76
    final public function isComment (): bool {
77
        return $this->getResourceSubtype() === self::TYPE_COMMENT_ADDED;
78
    }
79
80
    /**
81
     * @return bool
82
     */
83
    final public function isDueDate (): bool {
84
        return $this->getResourceSubtype() === self::TYPE_DUE_DATE_CHANGED;
85
    }
86
87
    /**
88
     * @return bool
89
     */
90
    final public function isEdited (): bool {
91
        return $this->_is('is_edited');
92
    }
93
94
    /**
95
     * @return bool
96
     */
97
    final public function isFromApi (): bool {
98
        return $this->getSource() === 'api';
99
    }
100
101
    /**
102
     * @return bool
103
     */
104
    final public function isFromWeb (): bool {
105
        return $this->getSource() === 'web';
106
    }
107
108
    /**
109
     * @return bool
110
     */
111
    final public function isLikedComment (): bool {
112
        return $this->getResourceSubtype() === self::TYPE_COMMENT_LIKED;
113
    }
114
115
    /**
116
     * @return bool
117
     */
118
    final public function isLikedTask (): bool {
119
        return $this->getResourceSubtype() === self::TYPE_LIKED;
120
    }
121
122
    /**
123
     * @return bool
124
     */
125
    final public function isPinned (): bool {
126
        return $this->_is('is_pinned');
127
    }
128
129
    /**
130
     * @return bool
131
     */
132
    final public function isTag (): bool {
133
        return $this->getResourceSubtype() === self::TYPE_TAGGED;
134
    }
135
136
    /**
137
     * @param bool $pinned
138
     * @return $this
139
     */
140
    final public function setPinned (bool $pinned) {
141
        return $this->_set('is_pinned', $pinned);
142
    }
143
144
}