PersonalAccessTokenRepository   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 19
dl 0
loc 45
c 0
b 0
f 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getSupportedFields() 0 9 1
A updatePersonalAccessToken() 0 7 1
A jsonToEntity() 0 3 1
A getBaseUri() 0 3 1
A createPersonalAccessToken() 0 7 1
A deletePersonalAccessToken() 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\Profile\Repository;
13
14
use Linode\Entity;
15
use Linode\Internal\AbstractRepository;
16
use Linode\Profile\PersonalAccessToken;
17
use Linode\Profile\PersonalAccessTokenRepositoryInterface;
18
19
/**
20
 * @codeCoverageIgnore This class was autogenerated.
21
 */
22
class PersonalAccessTokenRepository extends AbstractRepository implements PersonalAccessTokenRepositoryInterface
23
{
24
    public function createPersonalAccessToken(array $parameters = []): PersonalAccessToken
25
    {
26
        $response = $this->client->post($this->getBaseUri(), $parameters);
27
        $contents = $response->getBody()->getContents();
28
        $json     = json_decode($contents, true);
29
30
        return new PersonalAccessToken($this->client, $json);
31
    }
32
33
    public function updatePersonalAccessToken(int $tokenId, array $parameters = []): PersonalAccessToken
34
    {
35
        $response = $this->client->put(sprintf('%s/%s', $this->getBaseUri(), $tokenId), $parameters);
36
        $contents = $response->getBody()->getContents();
37
        $json     = json_decode($contents, true);
38
39
        return new PersonalAccessToken($this->client, $json);
40
    }
41
42
    public function deletePersonalAccessToken(int $tokenId): void
43
    {
44
        $this->client->delete(sprintf('%s/%s', $this->getBaseUri(), $tokenId));
45
    }
46
47
    protected function getBaseUri(): string
48
    {
49
        return '/profile/tokens';
50
    }
51
52
    protected function getSupportedFields(): array
53
    {
54
        return [
55
            PersonalAccessToken::FIELD_ID,
56
            PersonalAccessToken::FIELD_LABEL,
57
            PersonalAccessToken::FIELD_SCOPES,
58
            PersonalAccessToken::FIELD_CREATED,
59
            PersonalAccessToken::FIELD_TOKEN,
60
            PersonalAccessToken::FIELD_EXPIRY,
61
        ];
62
    }
63
64
    protected function jsonToEntity(array $json): Entity
65
    {
66
        return new PersonalAccessToken($this->client, $json);
67
    }
68
}
69