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.

Volume   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 134
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 4
dl 0
loc 134
ccs 32
cts 32
cp 1
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getAliases() 0 6 1
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 getMetadata() 0 6 1
A mergeMetadata() 0 6 1
A resetMetadata() 0 5 1
A parseMetadata() 0 5 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 getMetadata(): array
128 4
    {
129
        $response = $this->executeWithState($this->api->getVolumeMetadata());
130 4
        $this->metadata = $this->parseMetadata($response);
131 4
        return $this->metadata;
132
    }
133
134
    public function mergeMetadata(array $metadata)
135
    {
136
        $this->getMetadata();
137
        $this->metadata = array_merge($this->metadata, $metadata);
138
        $this->executeWithState($this->api->putVolumeMetadata());
139
    }
140
141
    public function resetMetadata(array $metadata)
142
    {
143
        $this->metadata = $metadata;
144
        $this->executeWithState($this->api->putVolumeMetadata());
145
    }
146
147
    public function parseMetadata(ResponseInterface $response): array
148
    {
149
        $json = Utils::jsonDecode($response);
150
        return isset($json['metadata']) ? $json['metadata'] : [];
151
    }
152
}
153