TimeEntry::all()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Matt
5
 * Date: 20/04/2016
6
 * Time: 2:32 PM
7
 */
8
9
namespace Freshdesk\Resources;
10
use Freshdesk\Resources\Traits\DeleteTrait;
11
use Freshdesk\Resources\Traits\UpdateTrait;
12
use Freshdesk\Resources\Traits\ViewTrait;
13
14
/**
15
 *
16
 * Time Entry resource
17
 *
18
 * Provide access to time entry resources
19
 *
20
 * @package Api\Resources
21
 */
22
class TimeEntry extends AbstractResource
23
{
24
25
    use ViewTrait, UpdateTrait, DeleteTrait;
26
27
    /**
28
     * The time entries resource endpoint
29
     *
30
     * @var string
31
     * @internal
32
     */
33
    protected $endpoint = '/time_entries';
34
35
    /**
36
     * The tickets resource endpoint
37
     *
38
     * @var string
39
     * @internal
40
     */
41
    private $ticketsEndpoint = '/tickets';
42
43
    /**
44
     * Creates the forums endpoint
45
     *
46
     * @param string $id
47
     * @return string
48
     * @internal
49
     */
50
    protected function ticketsEndpoint($id = null)
51
    {
52
        return $id === null ? $this->ticketsEndpoint : $this->ticketsEndpoint . '/' . $id;
53
    }
54
55
    /**
56
     *
57
     * Create a time entry for a ticket
58
     *
59
     * @api
60
     * @param int $id
61
     * @param array $data
62
     * @return array|null
63
     * @throws \Freshdesk\Exceptions\AccessDeniedException
64
     * @throws \Freshdesk\Exceptions\ApiException
65
     * @throws \Freshdesk\Exceptions\AuthenticationException
66
     * @throws \Freshdesk\Exceptions\ConflictingStateException
67
     * @throws \Freshdesk\Exceptions\NotFoundException
68
     * @throws \Freshdesk\Exceptions\RateLimitExceededException
69
     * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException
70
     * @throws \Freshdesk\Exceptions\MethodNotAllowedException
71
     * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException
72
     * @throws \Freshdesk\Exceptions\ValidationException
73
     */
74
    public function create($id, array $data)
75
    {
76
        return $this->api()->request('POST', $this->ticketsEndpoint($id . '/time_entries'), $data);
77
    }
78
79
    /**
80
     *
81
     * List time entries for a ticket
82
     *
83
     * @api
84
     * @param int $id
85
     * @param array|null $query
86
     * @return array|null
87
     * @throws \Freshdesk\Exceptions\AccessDeniedException
88
     * @throws \Freshdesk\Exceptions\ApiException
89
     * @throws \Freshdesk\Exceptions\AuthenticationException
90
     * @throws \Freshdesk\Exceptions\ConflictingStateException
91
     * @throws \Freshdesk\Exceptions\NotFoundException
92
     * @throws \Freshdesk\Exceptions\RateLimitExceededException
93
     * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException
94
     * @throws \Freshdesk\Exceptions\MethodNotAllowedException
95
     * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException
96
     * @throws \Freshdesk\Exceptions\ValidationException
97
     */
98
    public function all($id, array $query = null)
99
    {
100
        return $this->api()->request('GET', $this->ticketsEndpoint($id . '/time_entries'), null, $query);
101
    }
102
103
    /**
104
     *
105
     * Start / stop the timer
106
     *
107
     * @api
108
     * @param int $id
109
     * @return array|null
110
     * @throws \Freshdesk\Exceptions\AccessDeniedException
111
     * @throws \Freshdesk\Exceptions\ApiException
112
     * @throws \Freshdesk\Exceptions\AuthenticationException
113
     * @throws \Freshdesk\Exceptions\ConflictingStateException
114
     * @throws \Freshdesk\Exceptions\NotFoundException
115
     * @throws \Freshdesk\Exceptions\RateLimitExceededException
116
     * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException
117
     * @throws \Freshdesk\Exceptions\MethodNotAllowedException
118
     * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException
119
     * @throws \Freshdesk\Exceptions\ValidationException
120
     */
121
    public function toggle($id)
122
    {
123
        return $this->api()->request('PUT', $this->endpoint($id));
124
    }
125
126
}
127