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 (#152)
by Chris
01:53
created

Volume   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 138
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 3
dl 0
loc 138
ccs 32
cts 32
cp 1
rs 10
c 0
b 0
f 0

11 Methods

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