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

Snapshot::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 2
Metric Value
c 2
b 0
f 2
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
3
namespace OpenStack\BlockStorage\v2\Models;
4
5
use OpenStack\Common\Resource\AbstractResource;
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 Snapshot extends AbstractResource implements Listable, Creatable, Updateable, Deletable, Retrievable, HasMetadata
20
{
21
    use HasWaiterTrait;
22
23
    /** @var string */
24
    public $id;
25
26
    /** @var string */
27
    public $name;
28
29
    /** @var string */
30
    public $status;
31
32
    /** @var string */
33
    public $description;
34
35
    /** @var \DateTimeImmutable */
36
    public $createdAt;
37
38
    /** @var array */
39
    public $metadata = [];
40
41
    /** @var string */
42
    public $volumeId;
43
44
    /** @var int */
45
    public $size;
46
47
    protected $resourceKey = 'snapshot';
48
    protected $resourcesKey = 'snapshots';
49
50
    protected $aliases = [
51
        'created_at' => 'createdAt',
52
        'volume_id'  => 'volumeId',
53
    ];
54
55 2
    public function populateFromResponse(ResponseInterface $response)
56
    {
57 2
        parent::populateFromResponse($response);
58 2
        $this->metadata = $this->parseMetadata($response);
59 2
        return $this;
60
    }
61
62 1
    public function retrieve()
63
    {
64 1
        $response = $this->executeWithState($this->api->getSnapshot());
65 1
        return $this->populateFromResponse($response);
0 ignored issues
show
Bug introduced by
It seems like $response defined by $this->executeWithState(...is->api->getSnapshot()) on line 64 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...
66
    }
67
68
    /**
69
     * @param array $userOptions {@see \OpenStack\BlockStorage\v2\Api::postSnapshots}
70
     *
71
     * @return self
72
     */
73 1
    public function create(array $userOptions)
74
    {
75 1
        $response = $this->execute($this->api->postSnapshots(), $userOptions);
76 1
        return $this->populateFromResponse($response);
0 ignored issues
show
Bug introduced by
It seems like $response defined by $this->execute($this->ap...pshots(), $userOptions) on line 75 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...
77
    }
78
79 1
    public function update()
80
    {
81 1
        $this->executeWithState($this->api->putSnapshot());
82 1
    }
83
84 1
    public function delete()
85
    {
86 1
        $this->executeWithState($this->api->deleteSnapshot());
87 1
    }
88
89 2
    public function getMetadata()
90
    {
91 2
        $response = $this->executeWithState($this->api->getSnapshotMetadata());
92 2
        $this->metadata = $this->parseMetadata($response);
0 ignored issues
show
Bug introduced by
It seems like $response defined by $this->executeWithState(...>getSnapshotMetadata()) on line 91 can also be of type object<GuzzleHttp\Promise\PromiseInterface>; however, OpenStack\BlockStorage\v...apshot::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...
93 2
        return $this->metadata;
94
    }
95
96 1
    public function mergeMetadata(array $metadata)
97
    {
98 1
        $this->getMetadata();
99 1
        $this->metadata = array_merge($this->metadata, $metadata);
100 1
        $this->executeWithState($this->api->putSnapshotMetadata());
101 1
    }
102
103 1
    public function resetMetadata(array $metadata)
104
    {
105 1
        $this->metadata = $metadata;
106 1
        $this->executeWithState($this->api->putSnapshotMetadata());
107 1
    }
108
109 4
    public function parseMetadata(ResponseInterface $response)
110
    {
111 4
        $json = Utils::jsonDecode($response);
112 4
        return isset($json['metadata']) ? $json['metadata'] : [];
113
    }
114
}
115