RegionRepository::getSupportedFields()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
c 0
b 0
f 0
dl 0
loc 9
rs 10
cc 1
nc 1
nop 0
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\Regions\Repository;
13
14
use Linode\Entity;
15
use Linode\Internal\AbstractRepository;
16
use Linode\Regions\Region;
17
use Linode\Regions\RegionAvailability;
18
use Linode\Regions\RegionRepositoryInterface;
19
20
/**
21
 * @codeCoverageIgnore This class was autogenerated.
22
 */
23
class RegionRepository extends AbstractRepository implements RegionRepositoryInterface
24
{
25
    public function getRegionsAvailability(): array
26
    {
27
        $response = $this->client->get(sprintf('%s/availability', $this->getBaseUri()));
28
        $contents = $response->getBody()->getContents();
29
        $json     = json_decode($contents, true);
30
31
        return array_map(fn ($data) => new RegionAvailability($this->client, $data), $json['data']);
32
    }
33
34
    public function getRegionAvailability(string $regionId): RegionAvailability
35
    {
36
        $response = $this->client->get(sprintf('%s/%s/availability', $this->getBaseUri(), $regionId));
37
        $contents = $response->getBody()->getContents();
38
        $json     = json_decode($contents, true);
39
40
        return new RegionAvailability($this->client, $json);
41
    }
42
43
    protected function getBaseUri(): string
44
    {
45
        return '/regions';
46
    }
47
48
    protected function getSupportedFields(): array
49
    {
50
        return [
51
            Region::FIELD_ID,
52
            Region::FIELD_LABEL,
53
            Region::FIELD_COUNTRY,
54
            Region::FIELD_CAPABILITIES,
55
            Region::FIELD_STATUS,
56
            Region::FIELD_RESOLVERS,
57
        ];
58
    }
59
60
    protected function jsonToEntity(array $json): Entity
61
    {
62
        return new Region($this->client, $json);
63
    }
64
}
65