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 (#165)
by
unknown
01:39
created

Flavor   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 0
loc 85
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A populateFromResponse() 0 6 1
A retrieve() 0 5 1
A create() 0 5 1
A delete() 0 4 1
A getExtraSpecs() 0 6 1
A mergeExtraSpecs() 0 4 1
A deleteExtraSpec() 0 4 1
A parseExtraSpecs() 0 5 2
1
<?php declare(strict_types=1);
2
3
namespace OpenStack\Compute\v2\Models;
4
5
use OpenStack\Common\Resource\Creatable;
6
use OpenStack\Common\Resource\Deletable;
7
use OpenStack\Common\Resource\HasExtraSpecs;
8
use OpenStack\Common\Resource\OperatorResource;
9
use OpenStack\Common\Resource\Listable;
10
use OpenStack\Common\Resource\Retrievable;
11
use OpenStack\Common\Transport\Utils;
12
use Psr\Http\Message\ResponseInterface;
13
14
/**
15
 * Represents a Compute v2 Flavor.
16
 *
17
 * @property \OpenStack\Compute\v2\Api $api
18
 */
19
class Flavor extends OperatorResource implements Listable, Retrievable, Creatable, Deletable, HasExtraSpecs
20
{
21
    /** @var int */
22
    public $disk;
23
24
    /** @var string */
25
    public $id;
26
27
    /** @var string */
28
    public $name;
29
30
    /** @var int */
31
    public $ram;
32
33
    /** @var int */
34
    public $swap;
35
36
    /** @var int */
37
    public $vcpus;
38
39
    /** @var array */
40 1
    public $links;
41
42 1
    /** @var array */
43 1
    public $extraSpecs = [];
44 1
45
    protected $resourceKey = 'flavor';
46
    protected $resourcesKey = 'flavors';
47
48
    public function populateFromResponse(ResponseInterface $response): self
49
    {
50
        parent::populateFromResponse($response);
51
        $this->extraSpecs = $this->parseExtraSpecs($response);
52
        return $this;
53
    }
54
55
    /**
56
     * {@inheritDoc}
57
     */
58
    public function retrieve()
59
    {
60
        $response = $this->execute($this->api->getFlavor(), ['id' => (string)$this->id]);
61
        $this->populateFromResponse($response);
62
    }
63
64
    /**
65
     * {@inheritDoc}
66
     */
67
    public function create(array $userOptions): Creatable
68
    {
69
        $response = $this->execute($this->api->postFlavors(), $userOptions);
70
        return $this->populateFromResponse($response);
71
    }
72
73
    /**
74
     * {@inheritDoc}
75
     */
76
    public function delete()
77
    {
78
        $this->execute($this->api->deleteFlavor(), ['id' => (string)$this->id]);
79
    }
80
81
    public function getExtraSpecs(): array
82
    {
83
        $response = $this->executeWithState($this->api->getFlavorExtraSpecs());
84
        $this->extraSpecs = $this->parseExtraSpecs($response);
85
        return $this->extraSpecs;
86
    }
87
88
    public function mergeExtraSpecs(array $extraSpecs)
89
    {
90
        $this->execute($this->api->postFlavorExtraSpecs(), ['id' => $this->id, 'extraSpecs' => $extraSpecs]);
91
    }
92
93
    public function deleteExtraSpec($key)
94
    {
95
        $this->execute($this->api->deleteFlavorExtraSpecKey(), ['id' => $this->id, 'key' => $key]);
96
    }
97
98
    public function parseExtraSpecs(ResponseInterface $response): array
99
    {
100
        $json = Utils::jsonDecode($response);
101
        return isset($json['extra_specs']) ? $json['extra_specs'] : [];
102
    }
103
}
104