Comment::getAssignedByAttribute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Spinen\ClickUp;
4
5
use Carbon\Carbon;
6
use Spinen\ClickUp\Exceptions\InvalidRelationshipException;
7
use Spinen\ClickUp\Exceptions\ModelNotFoundException;
8
use Spinen\ClickUp\Exceptions\NoClientException;
9
use Spinen\ClickUp\Support\Model;
10
use Spinen\ClickUp\Support\Relations\ChildOf;
11
12
/**
13
 * Class Comment
14
 *
15
 * @package Spinen\ClickUp
16
 *
17
 * @property array $comments
18
 * @property array $relations
19
 * @property boolean $resolved
20
 * @property Carbon $date
21
 * @property integer $id
22
 * @property Member $assigned_by
23
 * @property Member $assignee
24
 * @property Member $user
25
 * @property string $hist_id
26
 * @property string $text
27
 */
28
class Comment extends Model
29
{
30
    /**
31
     * The attributes that should be cast to native types.
32
     *
33
     * @var array
34
     */
35
    protected $casts = [
36
        'date'     => 'datetime:Uv',
37
        'id'       => 'integer',
38
        'resolved' => 'boolean',
39
    ];
40
41
    /**
42
     * Path to API endpoint.
43
     *
44
     * @var string
45
     */
46
    protected $path = '/comment';
47
48
    /**
49
     * Accessor for Assignee.
50
     *
51
     * @param array $assignee
52
     *
53
     * @return Member
54
     * @throws NoClientException
55
     */
56 1
    public function getAssigneeAttribute($assignee): Member
57
    {
58 1
        return $this->givenOne(Member::class, $assignee);
59
    }
60
61
    /**
62
     * Accessor for AssignedBy.
63
     *
64
     * @param array $assigned_by
65
     *
66
     * @return Member
67
     * @throws NoClientException
68
     */
69 1
    public function getAssignedByAttribute($assigned_by): Member
70
    {
71 1
        return $this->givenOne(Member::class, $assigned_by);
72
    }
73
74
    /**
75
     * Accessor for User.
76
     *
77
     * @param array $user
78
     *
79
     * @return Member
80
     * @throws NoClientException
81
     */
82 1
    public function getUserAttribute($user): Member
83
    {
84 1
        return $this->givenOne(Member::class, $user);
85
    }
86
87
    /**
88
     * @return ChildOf
89
     * @throws InvalidRelationshipException
90
     * @throws ModelNotFoundException
91
     * @throws NoClientException
92
     */
93 2
    public function list(): ?ChildOf
94
    {
95 2
        return is_a($this->parentModel, TaskList::class) ? $this->childOf(TaskList::class) : null;
96
    }
97
98
    /**
99
     * @return ChildOf
100
     * @throws InvalidRelationshipException
101
     * @throws ModelNotFoundException
102
     * @throws NoClientException
103
     */
104 2
    public function task(): ?ChildOf
105
    {
106 2
        return is_a($this->parentModel, Task::class) ? $this->childOf(Task::class) : null;
107
    }
108
109
    /**
110
     * @return ChildOf
111
     * @throws InvalidRelationshipException
112
     * @throws ModelNotFoundException
113
     * @throws NoClientException
114
     */
115 2
    public function view(): ?ChildOf
116
    {
117 2
        return is_a($this->parentModel, View::class) ? $this->childOf(View::class) : null;
118
    }
119
}
120