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
Push — master ( 4ba218...ab686e )
by Jamie
04:16
created

Image::retrieve()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php declare (strict_types = 1);
2
3
namespace OpenStack\Compute\v2\Models;
4
5
use OpenCloud\Common\Resource\AbstractResource;
6
use OpenCloud\Common\Resource\Deletable;
7
use OpenCloud\Common\Resource\HasMetadata;
8
use OpenCloud\Common\Resource\Listable;
9
use OpenCloud\Common\Resource\Retrievable;
10
use OpenCloud\Common\Transport\Utils;
11
use Psr\Http\Message\ResponseInterface;
12
13
/**
14
 * Represents a Compute v2 Image
15
 *
16
 * @property \OpenStack\Compute\v2\Api $api
17
 */
18
class Image extends AbstractResource implements Listable, Retrievable, Deletable, HasMetadata
19
{
20
    /** @var string */
21
    public $id;
22
23
    /** @var array */
24
    public $links;
25
26
    /** @var array */
27
    public $metadata;
28
29
    /** @var int */
30
    public $minDisk;
31
32
    /** @var int */
33
    public $minRam;
34
35
    /** @var string */
36
    public $name;
37
38
    /** @var string */
39
    public $progress;
40
41
    /** @var string */
42
    public $status;
43
44
    /** @var \DateTimeImmutable */
45
    public $created;
46
47
    /** @var \DateTimeImmutable */
48
    public $updated;
49
50
    protected $resourceKey = 'image';
51
    protected $resourcesKey = 'images';
52
53
    /**
54 1
     * {@inheritDoc}
55
     */
56 1
    public function retrieve()
57 1
    {
58 1
        $response = $this->execute($this->api->getImage(), ['id' => (string)$this->id]);
59
        $this->populateFromResponse($response);
60
    }
61
62
    /**
63 1
     * {@inheritDoc}
64
     */
65 1
    public function delete()
66 1
    {
67
        $this->execute($this->api->deleteImage(), ['id' => (string)$this->id]);
68
    }
69
70
    /**
71
     * Retrieves metadata from the API.
72
     *
73 1
     * @return array
74
     */
75 1
    public function getMetadata(): array
76 1
    {
77
        $response = $this->execute($this->api->getImageMetadata(), ['id' => $this->id]);
78
        return $this->parseMetadata($response);
79
    }
80
81
    /**
82
     * Resets all the metadata for this image with the values provided. All existing metadata keys
83
     * will either be replaced or removed.
84
     *
85
     * @param array $metadata {@see \OpenStack\Compute\v2\Api::putImageMetadata}
86
     */
87 1
    public function resetMetadata(array $metadata)
88
    {
89 1
        $response = $this->execute($this->api->putImageMetadata(), ['id' => $this->id, 'metadata' => $metadata]);
90 1
        $this->metadata = $this->parseMetadata($response);
91
    }
92
93
    /**
94
     * Merges the existing metadata for the image with the values provided. Any existing keys
95
     * referenced in the user options will be replaced with the user's new values. All other
96
     * existing keys will remain unaffected.
97
     *
98
     * @param array $metadata {@see \OpenStack\Compute\v2\Api::postImageMetadata}
99
     */
100
    public function mergeMetadata(array $metadata)
101
    {
102 1
        $response = $this->execute($this->api->postImageMetadata(), ['id' => $this->id, 'metadata' => $metadata]);
103
        $this->metadata = $this->parseMetadata($response);
104 1
    }
105 1
106
    /**
107
     * Retrieve the value for a specific metadata key.
108
     *
109
     * @param string $key {@see \OpenStack\Compute\v2\Api::getImageMetadataKey}
110
     *
111
     * @return mixed
112
     */
113 View Code Duplication
    public function getMetadataItem(string $key)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
114
    {
115 1
        $response = $this->execute($this->api->getImageMetadataKey(), ['id' => $this->id, 'key' => $key]);
116
        $value = $this->parseMetadata($response)[$key];
117 1
        $this->metadata[$key] = $value;
118 1
        return $value;
119
    }
120
121
    /**
122
     * Remove a specific metadata key.
123
     *
124
     * @param string $key {@see \OpenStack\Compute\v2\Api::deleteImageMetadataKey}
125
     */
126 1 View Code Duplication
    public function deleteMetadataItem(string $key)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
127
    {
128 1
        if (isset($this->metadata[$key])) {
129 1
            unset($this->metadata[$key]);
130
        }
131
132
        $this->execute($this->api->deleteImageMetadataKey(), ['id' => $this->id, 'key' => $key]);
133
    }
134
135
    public function parseMetadata(ResponseInterface $response): array
136
    {
137
        return Utils::jsonDecode($response)['metadata'];
138
    }
139
}
140