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 (#50)
by Ha
02:21
created

Service   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 152
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 13
c 3
b 0
f 0
lcom 1
cbo 2
dl 0
loc 152
ccs 21
cts 21
cp 1
rs 10

12 Methods

Rating   Name   Duplication   Size   Complexity  
A createServer() 0 4 1
A listServers() 0 5 2
A getServer() 0 6 1
A listFlavors() 0 4 1
A getFlavor() 0 6 1
A createFlavor() 0 4 1
A listImages() 0 4 1
A getImage() 0 6 1
A listKeypairs() 0 4 1
A createKeypair() 0 4 1
A getKeypair() 0 6 1
A getLimits() 0 6 1
1
<?php declare (strict_types=1);
2
3
namespace OpenStack\Compute\v2;
4
5
use OpenCloud\Common\Service\AbstractService;
6
use OpenStack\Compute\v2\Models\Flavor;
7
use OpenStack\Compute\v2\Models\Image;
8
use OpenStack\Compute\v2\Models\Keypair;
9
use OpenStack\Compute\v2\Models\Limit;
10
use OpenStack\Compute\v2\Models\Server;
11
12
/**
13
 * Compute v2 service for OpenStack.
14
 *
15
 * @property \OpenStack\Compute\v2\Api $api
16
 */
17
class Service extends AbstractService
18
{
19
    /**
20
     * Create a new server resource. This operation will provision a new virtual machine on a host chosen by your
21
     * service API.
22
     *
23
     * @param array $options {@see \OpenStack\Compute\v2\Api::postServer}
24
     *
25 1
     * @return \OpenStack\Compute\v2\Models\Server
26
     */
27 1
    public function createServer(array $options): Server
28
    {
29
        return $this->model(Server::class)->create($options);
0 ignored issues
show
Bug introduced by
The method create() does not seem to exist on object<OpenCloud\Common\...urce\ResourceInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
30
    }
31
32
    /**
33
     * List servers.
34
     *
35
     * @param bool     $detailed Determines whether detailed information will be returned. If FALSE is specified, only
36
     *                           the ID, name and links attributes are returned, saving bandwidth.
37
     * @param array    $options  {@see \OpenStack\Compute\v2\Api::getServers}
38
     * @param callable $mapFn    A callable function that will be invoked on every iteration of the list.
39
     *
40 1
     * @return \Generator
41
     */
42 1
    public function listServers(bool $detailed = false, array $options = [], callable $mapFn = null): \Generator
43 1
    {
44
        $def = ($detailed === true) ? $this->api->getServersDetail() : $this->api->getServers();
45
        return $this->model(Server::class)->enumerate($def, $options, $mapFn);
46
    }
47
48
    /**
49
     * Retrieve a server object without calling the remote API. Any values provided in the array will populate the
50
     * empty object, allowing you greater control without the expense of network transactions. To call the remote API
51
     * and have the response populate the object, call {@see Server::retrieve}. For example:
52
     *
53
     * <code>$server = $service->getServer(['id' => '{serverId}']);</code>
54
     *
55
     * @param array $options An array of attributes that will be set on the {@see Server} object. The array keys need to
56
     *                       correspond to the class public properties.
57
     *
58 1
     * @return \OpenStack\Compute\v2\Models\Server
59
     */
60 1
    public function getServer(array $options = []): Server
61 1
    {
62 1
        $server = $this->model(Server::class);
63
        $server->populateFromArray($options);
64
        return $server;
65
    }
66
67
    /**
68
     * List flavors.
69
     *
70
     * @param array    $options {@see \OpenStack\Compute\v2\Api::getFlavors}
71
     * @param callable $mapFn   A callable function that will be invoked on every iteration of the list.
72
     *
73 1
     * @return \Generator
74
     */
75 1
    public function listFlavors(array $options = [], callable $mapFn = null): \Generator
76
    {
77
        return $this->model(Flavor::class)->enumerate($this->api->getFlavors(), $options, $mapFn);
78
    }
79
80
    /**
81
     * Retrieve a flavor object without calling the remote API. Any values provided in the array will populate the
82
     * empty object, allowing you greater control without the expense of network transactions. To call the remote API
83
     * and have the response populate the object, call {@see Flavor::retrieve}.
84
     *
85
     * @param array $options An array of attributes that will be set on the {@see Flavor} object. The array keys need to
86
     *                       correspond to the class public properties.
87
     *
88 1
     * @return \OpenStack\Compute\v2\Models\Flavor
89
     */
90 1
    public function getFlavor(array $options = []): Flavor
91 1
    {
92 1
        $flavor = $this->model(Flavor::class);
93
        $flavor->populateFromArray($options);
94
        return $flavor;
95
    }
96
97
    public function createFlavor(array $options = []): Flavor
98
    {
99
        return $this->model(Flavor::class)->create($options);
0 ignored issues
show
Bug introduced by
The method create() does not seem to exist on object<OpenCloud\Common\...urce\ResourceInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
100
    }
101
102
    /**
103 1
     * List images.
104
     *
105 1
     * @param array    $options {@see \OpenStack\Compute\v2\Api::getImages}
106
     * @param callable $mapFn   A callable function that will be invoked on every iteration of the list.
107
     *
108
     * @return \Generator
109
     */
110
    public function listImages(array $options = [], callable $mapFn = null): \Generator
111
    {
112
        return $this->model(Image::class)->enumerate($this->api->getImages(), $options, $mapFn);
113
    }
114
115
    /**
116
     * Retrieve an image object without calling the remote API. Any values provided in the array will populate the
117
     * empty object, allowing you greater control without the expense of network transactions. To call the remote API
118 1
     * and have the response populate the object, call {@see Image::retrieve}.
119
     *
120 1
     * @param array $options An array of attributes that will be set on the {@see Image} object. The array keys need to
121 1
     *                       correspond to the class public properties.
122 1
     *
123
     * @return \OpenStack\Compute\v2\Models\Image
124
     */
125
    public function getImage(array $options = []): Image
126
    {
127
        $image = $this->model(Image::class);
128
        $image->populateFromArray($options);
129
        return $image;
130
    }
131
132
    /**
133
     * List key pairs.
134
     *
135
     * @param array    $options {@see \OpenStack\Compute\v2\Api::getKeyPairs}
136
     * @param callable $mapFn   A callable function that will be invoked on every iteration of the list.
137
     *
138
     * @return \Generator
139
     */
140
    public function listKeypairs(array $options = [], callable $mapFn = null): \Generator
141
    {
142
        return $this->model(Keypair::class)->enumerate($this->api->getKeypairs(), $options, $mapFn);
143
    }
144
145
    public function createKeypair(array $options): Keypair
146
    {
147
        return $this->model(Keypair::class)->create($options);
0 ignored issues
show
Bug introduced by
The method create() does not seem to exist on object<OpenCloud\Common\...urce\ResourceInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
148
    }
149
150
    public function getKeypair(array $options = []): Keypair
151
    {
152
        $keypair = $this->model(Keypair::class);
153
        $keypair->populateFromArray($options);
154
        return $keypair;
155
    }
156
157
    /**
158
     * Shows rate and absolute limits for the tenant
159
     *
160
     * @return Limit
161
     */
162
    public function getLimits(): Limit
163
    {
164
        $limits = $this->model(Limit::class);
165
        $limits->populateFromResponse($this->execute($this->api->getLimits(), []));
166
        return $limits;
167
    }
168
}
169