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:56
created

Volume::resetStatus()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
crap 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
    {
115 1
        $response = $this->execute($this->api->resetVolumeStatus(), [
116
            'id' => $this->id,
117 1
            'status' => $status
118 1
        ]);
119 1
        $this->populateFromResponse($response);
120 1
    }
121
122 1
    public function getMetadata(): array
123
    {
124 1
        $response = $this->executeWithState($this->api->getVolumeMetadata());
125 1
        $this->metadata = $this->parseMetadata($response);
126 1
        return $this->metadata;
127
    }
128 4
129
    public function mergeMetadata(array $metadata)
130 4
    {
131 4
        $this->getMetadata();
132
        $this->metadata = array_merge($this->metadata, $metadata);
133
        $this->executeWithState($this->api->putVolumeMetadata());
134
    }
135
136
    public function resetMetadata(array $metadata)
137
    {
138
        $this->metadata = $metadata;
139
        $this->executeWithState($this->api->putVolumeMetadata());
140
    }
141
142
    public function parseMetadata(ResponseInterface $response): array
143
    {
144
        $json = Utils::jsonDecode($response);
145
        return isset($json['metadata']) ? $json['metadata'] : [];
146
    }
147
148
    public function extend(int $size_in_gb)
149
    {
150
        $response = $this->execute($this->api->extendVolume(), [
151
            'id' => $this->id,
152
            'new_size' => $size_in_gb
153
        ]);
154
        $this->populateFromResponse($response);
155
    }
156
}
157