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

SupportTicketReplyRepository   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 15
dl 0
loc 39
c 0
b 0
f 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getSupportedFields() 0 9 1
A jsonToEntity() 0 3 1
A getBaseUri() 0 3 1
A createTicketReply() 0 7 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\LinodeClient;
17
use Linode\Support\SupportTicketReply;
18
use Linode\Support\SupportTicketReplyRepositoryInterface;
19
20
/**
21
 * @codeCoverageIgnore This class was autogenerated.
22
 */
23
class SupportTicketReplyRepository extends AbstractRepository implements SupportTicketReplyRepositoryInterface
24
{
25
    /**
26
     * @param int $ticketId The ID of the Support Ticket.
27
     */
28
    public function __construct(LinodeClient $client, protected int $ticketId)
29
    {
30
        parent::__construct($client);
31
    }
32
33
    public function createTicketReply(array $parameters = []): SupportTicketReply
34
    {
35
        $response = $this->client->post($this->getBaseUri(), $parameters);
36
        $contents = $response->getBody()->getContents();
37
        $json     = json_decode($contents, true);
38
39
        return new SupportTicketReply($this->client, $json);
40
    }
41
42
    protected function getBaseUri(): string
43
    {
44
        return sprintf('/support/tickets/%s/replies', $this->ticketId);
45
    }
46
47
    protected function getSupportedFields(): array
48
    {
49
        return [
50
            SupportTicketReply::FIELD_ID,
51
            SupportTicketReply::FIELD_CREATED_BY,
52
            SupportTicketReply::FIELD_CREATED,
53
            SupportTicketReply::FIELD_GRAVATAR_ID,
54
            SupportTicketReply::FIELD_FROM_LINODE,
55
            SupportTicketReply::FIELD_DESCRIPTION,
56
        ];
57
    }
58
59
    protected function jsonToEntity(array $json): Entity
60
    {
61
        return new SupportTicketReply($this->client, $json);
62
    }
63
}
64