Ticket   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 138
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 7
dl 0
loc 138
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A restore() 0 6 1
A fields() 0 4 1
A conversations() 0 6 1
A timeEntries() 0 6 1
A search() 0 8 1
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
11
use Freshdesk\Resources\Traits\AllTrait;
12
use Freshdesk\Resources\Traits\CreateTrait;
13
use Freshdesk\Resources\Traits\DeleteTrait;
14
use Freshdesk\Resources\Traits\UpdateTrait;
15
use Freshdesk\Resources\Traits\ViewTrait;
16
17
/**
18
 * Ticket resource
19
 *
20
 * Provides access to ticket resources
21
 *
22
 * @package Api\Resources
23
 */
24
class Ticket extends AbstractResource
25
{
26
27
    use AllTrait, CreateTrait, ViewTrait, UpdateTrait, DeleteTrait;
28
29
    /**
30
     * The resource endpoint
31
     *
32
     * @var string
33
     */
34
    protected $endpoint = '/tickets';
35
36
    /**
37
     * Restore a ticket
38
     * 
39
     * Restores a previously deleted ticket
40
     *
41
     * @api
42
     * @param $id
43
     * @return mixed|null
44
     * @throws \Freshdesk\Exceptions\AccessDeniedException
45
     * @throws \Freshdesk\Exceptions\ApiException
46
     * @throws \Freshdesk\Exceptions\AuthenticationException
47
     * @throws \Freshdesk\Exceptions\ConflictingStateException
48
     * @throws \Freshdesk\Exceptions\NotFoundException
49
     * @throws \Freshdesk\Exceptions\RateLimitExceededException
50
     * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException
51
     * @throws \Freshdesk\Exceptions\MethodNotAllowedException
52
     * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException
53
     * @throws \Freshdesk\Exceptions\ValidationException
54
     */
55
    public function restore($id)
56
    {
57
        $end = $id . '/restore';
58
59
        return $this->api()->request('PUT', $this->endpoint($end));
60
    }
61
62
    /**
63
     * List ticket fields
64
     *
65
     * The agent whose credentials (API key or username/password) are being used to make this API call should be
66
     * authorised to view the ticket fields
67
     *
68
     * @param array|null $query
69
     * @return mixed|null
70
     * @throws \Freshdesk\Exceptions\AccessDeniedException
71
     * @throws \Freshdesk\Exceptions\ApiException
72
     * @throws \Freshdesk\Exceptions\AuthenticationException
73
     * @throws \Freshdesk\Exceptions\ConflictingStateException
74
     * @throws \Freshdesk\Exceptions\NotFoundException
75
     * @throws \Freshdesk\Exceptions\RateLimitExceededException
76
     * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException
77
     * @throws \Freshdesk\Exceptions\MethodNotAllowedException
78
     * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException
79
     * @throws \Freshdesk\Exceptions\ValidationException
80
     */
81
    public function fields(array $query = null)
82
    {
83
        return $this->api()->request('GET', '/ticket_fields', null, $query);
84
    }
85
86
    /**
87
     * List conversations associated with a ticket
88
     *
89
     * @param int $id The ticket id
90
     * @param array|null $query
91
     * @return mixed|null
92
     * @throws \Freshdesk\Exceptions\AccessDeniedException
93
     * @throws \Freshdesk\Exceptions\ApiException
94
     * @throws \Freshdesk\Exceptions\AuthenticationException
95
     * @throws \Freshdesk\Exceptions\ConflictingStateException
96
     * @throws \Freshdesk\Exceptions\NotFoundException
97
     * @throws \Freshdesk\Exceptions\RateLimitExceededException
98
     * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException
99
     * @throws \Freshdesk\Exceptions\MethodNotAllowedException
100
     * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException
101
     * @throws \Freshdesk\Exceptions\ValidationException
102
     */
103
    public function conversations($id, array $query = null)
104
    {
105
        $end = $id . '/conversations';
106
107
        return $this->api()->request('GET', $this->endpoint($end), null, $query);
108
    }
109
110
    /**
111
     * List time entries associated with a ticket
112
     *
113
     * @param int $id The ticket id
114
     * @param array|null $query
115
     * @return mixed|null
116
     * @throws \Freshdesk\Exceptions\AccessDeniedException
117
     * @throws \Freshdesk\Exceptions\ApiException
118
     * @throws \Freshdesk\Exceptions\AuthenticationException
119
     * @throws \Freshdesk\Exceptions\ConflictingStateException
120
     * @throws \Freshdesk\Exceptions\NotFoundException
121
     * @throws \Freshdesk\Exceptions\RateLimitExceededException
122
     * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException
123
     * @throws \Freshdesk\Exceptions\MethodNotAllowedException
124
     * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException
125
     * @throws \Freshdesk\Exceptions\ValidationException
126
     */
127
    public function timeEntries($id, array $query = null)
128
    {
129
        $end = $id . '/time_entries';
130
131
        return $this->api()->request('GET', $this->endpoint($end), null, $query);
132
    }
133
    
134
    /**
135
     * Filters by ticket fields
136
     *
137
     * Make sure to pass a valid $filtersQuery string example: "type:question"
138
     *
139
     * @api
140
     * @param string $filtersQuery
141
     * @return array|null
142
     * @throws \Freshdesk\Exceptions\AccessDeniedException
143
     * @throws \Freshdesk\Exceptions\ApiException
144
     * @throws \Freshdesk\Exceptions\AuthenticationException
145
     * @throws \Freshdesk\Exceptions\ConflictingStateException
146
     * @throws \Freshdesk\Exceptions\NotFoundException
147
     * @throws \Freshdesk\Exceptions\RateLimitExceededException
148
     * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException
149
     * @throws \Freshdesk\Exceptions\MethodNotAllowedException
150
     * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException
151
     * @throws \Freshdesk\Exceptions\ValidationException
152
     */
153
    public function search(string $filtersQuery)
154
    {
155
        $end = '/search'.$this->endpoint();
156
        $query = [
157
            'query' => '"'.$filtersQuery.'"',
158
        ];
159
        return $this->api()->request('GET', $end, null, $query);
160
    }
161
}
162