Passed
Push — master ( bfa63a...41a424 )
by Artem
01:47
created

EntityTransferRepository::jsonToEntity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 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\Account\Repository;
13
14
use Linode\Account\EntityTransfer;
15
use Linode\Account\EntityTransferRepositoryInterface;
16
use Linode\Entity;
17
use Linode\Internal\AbstractRepository;
18
19
/**
20
 * @codeCoverageIgnore This class was autogenerated.
21
 */
22
class EntityTransferRepository extends AbstractRepository implements EntityTransferRepositoryInterface
23
{
24
    public function createEntityTransfer(array $parameters = []): EntityTransfer
25
    {
26
        $response = $this->client->post($this->getBaseUri(), $parameters);
27
        $contents = $response->getBody()->getContents();
28
        $json     = json_decode($contents, true);
29
30
        return new EntityTransfer($this->client, $json);
31
    }
32
33
    public function deleteEntityTransfer(string $token): void
34
    {
35
        $this->client->delete(sprintf('%s/%s', $this->getBaseUri(), $token));
36
    }
37
38
    public function acceptEntityTransfer(string $token): void
39
    {
40
        $this->client->post(sprintf('%s/%s/accept', $this->getBaseUri(), $token));
41
    }
42
43
    protected function getBaseUri(): string
44
    {
45
        return '/account/entity-transfers';
46
    }
47
48
    protected function getSupportedFields(): array
49
    {
50
        return [
51
            EntityTransfer::FIELD_TOKEN,
52
            EntityTransfer::FIELD_STATUS,
53
            EntityTransfer::FIELD_EXPIRY,
54
            EntityTransfer::FIELD_IS_SENDER,
55
            EntityTransfer::FIELD_CREATED,
56
            EntityTransfer::FIELD_UPDATED,
57
            EntityTransfer::FIELD_ENTITIES,
58
        ];
59
    }
60
61
    protected function jsonToEntity(array $json): Entity
62
    {
63
        return new EntityTransfer($this->client, $json);
64
    }
65
}
66