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.
Passed
Push — master ( 307cce...27531d )
by Jamie
04:17 queued 15s
created

Volume::getMetadata()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4286
cc 1
eloc 4
nc 1
nop 0
crap 1
1
<?php
2
namespace OpenStack\BlockStorage\v2\Models;
3
4
use OpenStack\Common\Resource\AbstractResource;
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 AbstractResource 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 array */
56
    public $metadata = [];
57
58
    protected $resourceKey = 'volume';
59
    protected $resourcesKey = 'volumes';
60
    protected $aliases = [
61
        'availability_zone' => 'availabilityZone',
62
        'source_volid'      => 'sourceVolumeId',
63
        'snapshot_id'       => 'snapshotId',
64
        'created_at'        => 'createdAt',
65
        'volume_type'       => 'volumeTypeName',
66
    ];
67
68 3
    public function populateFromResponse(ResponseInterface $response)
69
    {
70 3
        parent::populateFromResponse($response);
71 3
        $this->metadata = $this->parseMetadata($response);
72 3
        return $this;
73
    }
74
75 1
    public function retrieve()
76
    {
77 1
        $response = $this->executeWithState($this->api->getVolume());
78 1
        return $this->populateFromResponse($response);
0 ignored issues
show
Bug introduced by
It seems like $response defined by $this->executeWithState($this->api->getVolume()) on line 77 can also be of type object<GuzzleHttp\Promise\PromiseInterface>; however, OpenStack\BlockStorage\v...:populateFromResponse() does only seem to accept object<Psr\Http\Message\ResponseInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
79
    }
80
81
    /**
82
     * @param array $userOptions {@see \OpenStack\BlockStorage\v2\Api::postVolumes}
83
     *
84
     * @return self
85
     */
86 1
    public function create(array $userOptions)
87
    {
88 1
        $response = $this->execute($this->api->postVolumes(), $userOptions);
89 1
        return $this->populateFromResponse($response);
0 ignored issues
show
Bug introduced by
It seems like $response defined by $this->execute($this->ap...olumes(), $userOptions) on line 88 can also be of type object<GuzzleHttp\Promise\PromiseInterface>; however, OpenStack\BlockStorage\v...:populateFromResponse() does only seem to accept object<Psr\Http\Message\ResponseInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
90
    }
91
92
    /**
93
     * @return self
94
     */
95 1
    public function update()
96
    {
97 1
        $response = $this->executeWithState($this->api->putVolume());
98 1
        return $this->populateFromResponse($response);
0 ignored issues
show
Bug introduced by
It seems like $response defined by $this->executeWithState($this->api->putVolume()) on line 97 can also be of type object<GuzzleHttp\Promise\PromiseInterface>; however, OpenStack\BlockStorage\v...:populateFromResponse() does only seem to accept object<Psr\Http\Message\ResponseInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
99
    }
100
101 1
    public function delete()
102
    {
103 1
        $this->executeWithState($this->api->deleteVolume());
104 1
    }
105
106 1
    public function getMetadata()
107
    {
108 1
        $response = $this->executeWithState($this->api->getVolumeMetadata());
109 1
        $this->metadata = $this->parseMetadata($response);
0 ignored issues
show
Bug introduced by
It seems like $response defined by $this->executeWithState(...i->getVolumeMetadata()) on line 108 can also be of type object<GuzzleHttp\Promise\PromiseInterface>; however, OpenStack\BlockStorage\v...Volume::parseMetadata() does only seem to accept object<Psr\Http\Message\ResponseInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
110 1
        return $this->metadata;
111
    }
112
113 1
    public function mergeMetadata(array $metadata)
114
    {
115 1
        $this->getMetadata();
116 1
        $this->metadata = array_merge($this->metadata, $metadata);
117 1
        $this->executeWithState($this->api->putVolumeMetadata());
118 1
    }
119
120 1
    public function resetMetadata(array $metadata)
121
    {
122 1
        $this->metadata = $metadata;
123 1
        $this->executeWithState($this->api->putVolumeMetadata());
124 1
    }
125
126 4
    public function parseMetadata(ResponseInterface $response)
127
    {
128 4
        $json = Utils::jsonDecode($response);
129 4
        return isset($json['metadata']) ? $json['metadata'] : [];
130
    }
131
}
132