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 (#159)
by Roman
01:49
created

Snapshot   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

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

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getAlias() 0 12 2
A populateFromResponse() 0 6 1
A retrieve() 0 5 1
A create() 0 5 1
A update() 0 4 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
3
namespace OpenStack\BlockStorage\v2\Models;
4
5
use OpenStack\Common\Resource\Alias;
6
use OpenStack\Common\Resource\OperatorResource;
7
use OpenStack\Common\Resource\Creatable;
8
use OpenStack\Common\Resource\Deletable;
9
use OpenStack\Common\Resource\HasMetadata;
10
use OpenStack\Common\Resource\HasWaiterTrait;
11
use OpenStack\Common\Resource\Listable;
12
use OpenStack\Common\Resource\Retrievable;
13
use OpenStack\Common\Resource\Updateable;
14
use OpenStack\Common\Transport\Utils;
15
use Psr\Http\Message\ResponseInterface;
16
17
/**
18
 * @property \OpenStack\BlockStorage\v2\Api $api
19
 */
20
class Snapshot extends OperatorResource implements Listable, Creatable, Updateable, Deletable, Retrievable, HasMetadata
21
{
22
    use HasWaiterTrait;
23
24
    /** @var string */
25
    public $id;
26
27
    /** @var string */
28
    public $name;
29
30
    /** @var string */
31
    public $status;
32
33
    /** @var string */
34
    public $description;
35
36
    /** @var \DateTimeImmutable */
37
    public $createdAt;
38
39
    /** @var array */
40
    public $metadata = [];
41
42
    /** @var string */
43
    public $volumeId;
44
45
    /** @var int */
46
    public $size;
47
48
    protected $resourceKey = 'snapshot';
49
    protected $resourcesKey = 'snapshots';
50
    protected $markerKey = 'id';
51
52
    /**
53
     * @inheritdoc
54
     */
55
    protected static function getAlias(): Alias
56 2
    {
57
        $alias = parent::getAlias();
58 2
59 2
        if (!$alias->hasAliases(self::class)) {
60 2
            $alias
61
                ->add(self::class, 'volume_id', 'volumeId')
62
                ->add(self::class, 'created_at', 'createdAt', \DateTimeImmutable::class);
63 1
        }
64
65 1
        return $alias;
66 1
    }
67
68
    public function populateFromResponse(ResponseInterface $response): self
69
    {
70
        parent::populateFromResponse($response);
71
        $this->metadata = $this->parseMetadata($response);
72
        return $this;
73
    }
74 1
75
    public function retrieve()
76 1
    {
77 1
        $response = $this->executeWithState($this->api->getSnapshot());
78
        $this->populateFromResponse($response);
79
    }
80 1
81
    /**
82 1
     * @param array $userOptions {@see \OpenStack\BlockStorage\v2\Api::postSnapshots}
83 1
     *
84
     * @return Creatable
85 1
     */
86
    public function create(array $userOptions): Creatable
87 1
    {
88 1
        $response = $this->execute($this->api->postSnapshots(), $userOptions);
89
        return $this->populateFromResponse($response);
90 2
    }
91
92 2
    public function update()
93 2
    {
94 2
        $this->executeWithState($this->api->putSnapshot());
95
    }
96
97 1
    public function delete()
98
    {
99 1
        $this->executeWithState($this->api->deleteSnapshot());
100 1
    }
101 1
102 1
    public function getMetadata(): array
103
    {
104 1
        $response = $this->executeWithState($this->api->getSnapshotMetadata());
105
        $this->metadata = $this->parseMetadata($response);
106 1
        return $this->metadata;
107 1
    }
108 1
109
    public function mergeMetadata(array $metadata)
110 4
    {
111
        $this->getMetadata();
112 4
        $this->metadata = array_merge($this->metadata, $metadata);
113 4
        $this->executeWithState($this->api->putSnapshotMetadata());
114
    }
115
116
    public function resetMetadata(array $metadata)
117
    {
118
        $this->metadata = $metadata;
119
        $this->executeWithState($this->api->putSnapshotMetadata());
120
    }
121
122
    public function parseMetadata(ResponseInterface $response): array
123
    {
124
        $json = Utils::jsonDecode($response);
125
        return isset($json['metadata']) ? $json['metadata'] : [];
126
    }
127
}
128