Time::getUserAttribute()   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 Spinen\ClickUp\Exceptions\InvalidRelationshipException;
6
use Spinen\ClickUp\Exceptions\ModelNotFoundException;
7
use Spinen\ClickUp\Exceptions\NoClientException;
8
use Spinen\ClickUp\Support\Collection;
9
use Spinen\ClickUp\Support\Model;
10
use Spinen\ClickUp\Support\Relations\ChildOf;
11
12
/**
13
 * Class Time
14
 *
15
 * @package Spinen\ClickUp
16
 *
17
 * @property Collection $intervals
18
 * @property integer $time
19
 * @property Member $user
20
 * @property Task $task
21
 */
22
class Time extends Model
23
{
24
    /**
25
     * The attributes that should be cast to native types.
26
     *
27
     * @var array
28
     */
29
    protected $casts = [
30
        'time' => 'integer',
31
    ];
32
33
    /**
34
     * Path to API endpoint.
35
     *
36
     * @var string
37
     */
38
    protected $path = '/time';
39
40
    /**
41
     * Some of the responses have the data under a property
42
     *
43
     * @var string|null
44
     */
45
    protected $responseKey = 'data';
46
47
    /**
48
     * Accessor for Intervals.
49
     *
50
     * @param array $intervals
51
     *
52
     * @return Collection
53
     * @throws NoClientException
54
     */
55 1
    public function getIntervalsAttribute(array $intervals): Collection
56
    {
57 1
        return $this->givenMany(Interval::class, $intervals);
58
    }
59
60
    /**
61
     * Accessor for User.
62
     *
63
     * @param array $user
64
     *
65
     * @return Member
66
     * @throws NoClientException
67
     */
68 1
    public function getUserAttribute($user): Member
69
    {
70 1
        return $this->givenOne(Member::class, $user);
71
    }
72
73
    /**
74
     * @return ChildOf
75
     * @throws InvalidRelationshipException
76
     * @throws ModelNotFoundException
77
     * @throws NoClientException
78
     */
79 1
    public function task(): ChildOf
80
    {
81 1
        return $this->childOf(Task::class);
82
    }
83
}
84