Goal   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 23
c 1
b 0
f 0
dl 0
loc 81
ccs 8
cts 8
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A folder() 0 3 1
A team() 0 3 1
A getMembersAttribute() 0 3 1
A getOwnersAttribute() 0 3 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\Collection;
10
use Spinen\ClickUp\Support\Model;
11
use Spinen\ClickUp\Support\Relations\BelongsTo;
12
use Spinen\ClickUp\Support\Relations\ChildOf;
13
14
/**
15
 * Class Goal
16
 *
17
 * @package Spinen\ClickUp
18
 *
19
 * @property array $history
20
 * @property array $key_results
21
 * @property array $reactions
22
 * @property boolean $archived
23
 * @property boolean $multiple_owners
24
 * @property boolean $pinned
25
 * @property boolean $private
26
 * @property Carbon $date_created
27
 * @property Carbon $due_date
28
 * @property Carbon $last_update
29
 * @property Carbon $start_date
30
 * @property Collection $members
31
 * @property Collection $owners
32
 * @property float $percent_completed
33
 * @property Folder $folder
34
 * @property integer $creator
35
 * @property integer $folder_id
36
 * @property integer $key_result_count
37
 * @property integer $owner
38
 * @property integer $pretty_id
39
 * @property integer $team_id
40
 * @property string $color
41
 * @property string $description
42
 * @property string $id
43
 * @property string $name
44
 * @property Team $team
45
 */
46
class Goal extends Model
47
{
48
    /**
49
     * The attributes that should be cast to native types.
50
     *
51
     * @var array
52
     */
53
    protected $casts = [
54
        'archived'          => 'boolean',
55
        'creator'           => 'integer',
56
        'date_created'      => 'datetime:Uv',
57
        'due_date'          => 'datetime:Uv',
58
        'folder_id'         => 'integer',
59
        'id'                => 'string',
60
        'key_result_count'  => 'integer',
61
        'last_update'       => 'datetime:Uv',
62
        'multiple_owners'   => 'boolean',
63
        'owner'             => 'integer',
64
        'percent_completed' => 'float',
65
        'pinned'            => 'boolean',
66
        'pretty_id'         => 'integer',
67
        'private'           => 'boolean',
68
        'start_date'        => 'datetime:Uv',
69
        'team_id'           => 'integer',
70
    ];
71
72
    // TODO: Setup creator & owner as a "BelongsTo" (need API resource to look up a Member)
73
74
    /**
75
     * Path to API endpoint.
76
     *
77
     * @var string
78
     */
79
    protected $path = '/goal';
80
81
    /**
82
     * Accessor for Owners.
83
     *
84
     * @param array $owners
85
     *
86
     * @return Collection
87
     * @throws NoClientException
88
     */
89 1
    public function getOwnersAttribute(array $owners): Collection
90
    {
91 1
        return $this->givenMany(Member::class, $owners);
92
    }
93
94
    /**
95
     * Accessor for Members.
96
     *
97
     * @param array $members
98
     *
99
     * @return Collection
100
     * @throws NoClientException
101
     */
102 1
    public function getMembersAttribute(array $members): Collection
103
    {
104 1
        return $this->givenMany(Member::class, $members, true);
105
    }
106
107
    /**
108
     * @return BelongsTo
109
     * @throws InvalidRelationshipException
110
     * @throws ModelNotFoundException
111
     * @throws NoClientException
112
     */
113 1
    public function folder(): BelongsTo
114
    {
115 1
        return $this->belongsTo(Folder::class);
116
    }
117
118
    /**
119
     * @return ChildOf
120
     * @throws InvalidRelationshipException
121
     * @throws ModelNotFoundException
122
     * @throws NoClientException
123
     */
124 1
    public function team(): ChildOf
125
    {
126 1
        return $this->childOf(Team::class);
127
    }
128
}
129