GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#187)
by Chris
07:33
created

Volume::getMetadata()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 0
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
crap 2
1
<?php declare(strict_types=1);
2
namespace OpenStack\BlockStorage\v2\Models;
3
4
use OpenStack\Common\Resource\Alias;
5
use OpenStack\Common\Resource\OperatorResource;
6
use OpenStack\Common\Resource\Creatable;
7
use OpenStack\Common\Resource\Deletable;
8
use OpenStack\Common\Resource\HasMetadata;
9
use OpenStack\Common\Resource\HasWaiterTrait;
10
use OpenStack\Common\Resource\Listable;
11
use OpenStack\Common\Resource\Retrievable;
12
use OpenStack\Common\Resource\Updateable;
13
use OpenStack\Common\Transport\Utils;
14
use Psr\Http\Message\ResponseInterface;
15
16
/**
17
 * @property \OpenStack\BlockStorage\v2\Api $api
18
 */
19
class Volume extends OperatorResource implements Creatable, Listable, Updateable, Deletable, Retrievable, HasMetadata
20
{
21
    use HasWaiterTrait;
22
23
    /** @var string */
24
    public $id;
25
26
    /** @var int */
27
    public $size;
28
29
    /** @var string */
30
    public $status;
31
32
    /** @var string */
33
    public $name;
34
35
    /** @var array */
36
    public $attachments;
37
38
    /** @var string */
39
    public $availabilityZone;
40
41
    /** @var \DateTimeImmutable */
42
    public $createdAt;
43
44
    /** @var string */
45
    public $description;
46
47
    /** @var string */
48
    public $volumeTypeName;
49
50
    /** @var string */
51
    public $snapshotId;
52
53
    /** @var string */
54
    public $sourceVolumeId;
55
56
    /** @var string */
57
    public $tenantId;
58
59
    /** @var string */
60
    public $host;
61
62
    /** @var array */
63
    public $metadata = [];
64
65
    /** @var array */
66
    public $volumeImageMetadata = [];
67
68
    protected $resourceKey = 'volume';
69
    protected $resourcesKey = 'volumes';
70 3
    protected $markerKey = 'id';
71
72 3
    protected $aliases = [
73 3
        'availability_zone'            => 'availabilityZone',
74 3
        'source_volid'                 => 'sourceVolumeId',
75
        'snapshot_id'                  => 'snapshotId',
76
        'volume_type'                  => 'volumeTypeName',
77 1
        'os-vol-tenant-attr:tenant_id' => 'tenantId',
78
        'os-vol-host-attr:host'        => 'host',
79 1
        'volume_image_metadata'        => 'volumeImageMetadata',
80 1
    ];
81
82
    /**
83
     * @inheritdoc
84
     */
85
    protected function getAliases(): array
86
    {
87
        return parent::getAliases() + [
88 1
            'created_at' => new Alias('createdAt', \DateTimeImmutable::class)
89
        ];
90 1
    }
91 1
92
    public function populateFromResponse(ResponseInterface $response): self
93
    {
94
        parent::populateFromResponse($response);
95
        $this->metadata = $this->parseMetadata($response);
96
        return $this;
97 1
    }
98
99 1
    public function retrieve()
100 1
    {
101
        $response = $this->executeWithState($this->api->getVolume());
102
        $this->populateFromResponse($response);
103 1
    }
104
105 1
    /**
106 1
     * @param array $userOptions {@see \OpenStack\BlockStorage\v2\Api::postVolumes}
107
     *
108 1
     * @return Creatable
109
     */
110 1
    public function create(array $userOptions): Creatable
111 1
    {
112 1
        $response = $this->execute($this->api->postVolumes(), $userOptions);
113
        return $this->populateFromResponse($response);
114
    }
115 1
116
    public function update()
117 1
    {
118 1
        $response = $this->executeWithState($this->api->putVolume());
119 1
        $this->populateFromResponse($response);
120 1
    }
121
122 1
    public function delete()
123
    {
124 1
        $this->executeWithState($this->api->deleteVolume());
125 1
    }
126 1
127
    public function resetStatus(string $status)
128 4
    {
129
        $response = $this->execute($this->api->resetVolumeStatus(), [
130 4
            'id' => $this->id,
131 4
            'status' => $status
132
        ]);
133
        $this->populateFromResponse($response);
134
    }
135
136
    public function getMetadata(): array
137
    {
138
        $response = $this->executeWithState($this->api->getVolumeMetadata());
139
        $this->metadata = $this->parseMetadata($response);
140
        return $this->metadata;
141
    }
142
143
    public function mergeMetadata(array $metadata)
144
    {
145
        $this->getMetadata();
146
        $this->metadata = array_merge($this->metadata, $metadata);
147
        $this->executeWithState($this->api->putVolumeMetadata());
148
    }
149
150
    public function resetMetadata(array $metadata)
151
    {
152
        $this->metadata = $metadata;
153
        $this->executeWithState($this->api->putVolumeMetadata());
154
    }
155
156
    public function parseMetadata(ResponseInterface $response): array
157
    {
158
        $json = Utils::jsonDecode($response);
159
        return isset($json['metadata']) ? $json['metadata'] : [];
160
    }
161
162
    public function extend(int $size_in_gb)
163
    {
164
        $response = $this->execute($this->api->extendVolume(), [
165
            'id' => $this->id,
166
            'new_size' => $size_in_gb
167
        ]);
168
        $this->populateFromResponse($response);
169
    }
170
}
171