Passed
Push — master ( 0676a7...01ab94 )
by Artem
11:54
created

SupportTicketRepository   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 27
dl 0
loc 55
c 0
b 0
f 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getSupportedFields() 0 16 1
A createTicket() 0 7 1
A createTicketAttachment() 0 10 1
A jsonToEntity() 0 3 1
A closeTicket() 0 3 1
A getBaseUri() 0 3 1
1
<?php
2
3
// ---------------------------------------------------------------------
4
//
5
//  Copyright (C) 2018-2024 Artem Rodygin
6
//
7
//  You should have received a copy of the MIT License along with
8
//  this file. If not, see <https://opensource.org/licenses/MIT>.
9
//
10
// ---------------------------------------------------------------------
11
12
namespace Linode\Support\Repository;
13
14
use Linode\Entity;
15
use Linode\Internal\AbstractRepository;
16
use Linode\Support\SupportTicket;
17
use Linode\Support\SupportTicketRepositoryInterface;
18
19
/**
20
 * @codeCoverageIgnore This class was autogenerated.
21
 */
22
class SupportTicketRepository extends AbstractRepository implements SupportTicketRepositoryInterface
23
{
24
    public function createTicket(array $parameters = []): SupportTicket
25
    {
26
        $response = $this->client->post($this->getBaseUri(), $parameters);
27
        $contents = $response->getBody()->getContents();
28
        $json     = json_decode($contents, true);
29
30
        return new SupportTicket($this->client, $json);
31
    }
32
33
    public function createTicketAttachment(int $ticketId, string $file): void
34
    {
35
        $options = [
36
            'multipart' => [
37
                'name'     => 'file',
38
                'contents' => fopen($file, 'r'),
39
            ],
40
        ];
41
42
        $this->client->post(sprintf('%s/%s/attachments', $this->getBaseUri(), $ticketId), [], $options);
43
    }
44
45
    public function closeTicket(int $ticketId): void
46
    {
47
        $this->client->post(sprintf('%s/%s/close', $this->getBaseUri(), $ticketId));
48
    }
49
50
    protected function getBaseUri(): string
51
    {
52
        return '/support/tickets';
53
    }
54
55
    protected function getSupportedFields(): array
56
    {
57
        return [
58
            SupportTicket::FIELD_ID,
59
            SupportTicket::FIELD_SUMMARY,
60
            SupportTicket::FIELD_OPENED_BY,
61
            SupportTicket::FIELD_OPENED,
62
            SupportTicket::FIELD_DESCRIPTION,
63
            SupportTicket::FIELD_ENTITY,
64
            SupportTicket::FIELD_GRAVATAR_ID,
65
            SupportTicket::FIELD_STATUS,
66
            SupportTicket::FIELD_CLOSABLE,
67
            SupportTicket::FIELD_UPDATED_BY,
68
            SupportTicket::FIELD_UPDATED,
69
            SupportTicket::FIELD_CLOSED,
70
            SupportTicket::FIELD_ATTACHMENTS,
71
        ];
72
    }
73
74
    protected function jsonToEntity(array $json): Entity
75
    {
76
        return new SupportTicket($this->client, $json);
77
    }
78
}
79