1 | <?php declare (strict_types=1); |
||
18 | class Service extends AbstractService |
||
19 | { |
||
20 | /** |
||
21 | * Create a new server resource. This operation will provision a new virtual machine on a host chosen by your |
||
22 | * service API. |
||
23 | * |
||
24 | * @param array $options {@see \OpenStack\Compute\v2\Api::postServer} |
||
25 | 1 | * |
|
26 | * @return \OpenStack\Compute\v2\Models\Server |
||
27 | 1 | */ |
|
28 | public function createServer(array $options): Server |
||
32 | |||
33 | /** |
||
34 | * List servers. |
||
35 | * |
||
36 | * @param bool $detailed Determines whether detailed information will be returned. If FALSE is specified, only |
||
37 | * the ID, name and links attributes are returned, saving bandwidth. |
||
38 | * @param array $options {@see \OpenStack\Compute\v2\Api::getServers} |
||
39 | * @param callable $mapFn A callable function that will be invoked on every iteration of the list. |
||
40 | 1 | * |
|
41 | * @return \Generator |
||
42 | 1 | */ |
|
43 | 1 | public function listServers(bool $detailed = false, array $options = [], callable $mapFn = null): \Generator |
|
48 | |||
49 | /** |
||
50 | * Retrieve a server object without calling the remote API. Any values provided in the array will populate the |
||
51 | * empty object, allowing you greater control without the expense of network transactions. To call the remote API |
||
52 | * and have the response populate the object, call {@see Server::retrieve}. For example: |
||
53 | * |
||
54 | * <code>$server = $service->getServer(['id' => '{serverId}']);</code> |
||
55 | * |
||
56 | * @param array $options An array of attributes that will be set on the {@see Server} object. The array keys need to |
||
57 | * correspond to the class public properties. |
||
58 | 1 | * |
|
59 | * @return \OpenStack\Compute\v2\Models\Server |
||
60 | 1 | */ |
|
61 | 1 | public function getServer(array $options = []): Server |
|
67 | |||
68 | /** |
||
69 | * List flavors. |
||
70 | * |
||
71 | * @param array $options {@see \OpenStack\Compute\v2\Api::getFlavors} |
||
72 | * @param callable $mapFn A callable function that will be invoked on every iteration of the list. |
||
73 | 1 | * |
|
74 | * @return \Generator |
||
75 | 1 | */ |
|
76 | public function listFlavors(array $options = [], callable $mapFn = null): \Generator |
||
80 | |||
81 | /** |
||
82 | * Retrieve a flavor object without calling the remote API. Any values provided in the array will populate the |
||
83 | * empty object, allowing you greater control without the expense of network transactions. To call the remote API |
||
84 | * and have the response populate the object, call {@see Flavor::retrieve}. |
||
85 | * |
||
86 | * @param array $options An array of attributes that will be set on the {@see Flavor} object. The array keys need to |
||
87 | * correspond to the class public properties. |
||
88 | 1 | * |
|
89 | * @return \OpenStack\Compute\v2\Models\Flavor |
||
90 | 1 | */ |
|
91 | 1 | public function getFlavor(array $options = []): Flavor |
|
97 | |||
98 | /** |
||
99 | * Create a new flavor resource. |
||
100 | * |
||
101 | * @param array $options {@see \OpenStack\Compute\v2\Api::postFlavors} |
||
102 | * |
||
103 | 1 | * @return Flavor |
|
104 | */ |
||
105 | 1 | public function createFlavor(array $options = []): Flavor |
|
106 | { |
||
107 | return $this->model(Flavor::class)->create($options); |
||
108 | } |
||
109 | |||
110 | /** |
||
111 | * List images. |
||
112 | * |
||
113 | * @param array $options {@see \OpenStack\Compute\v2\Api::getImages} |
||
114 | * @param callable $mapFn A callable function that will be invoked on every iteration of the list. |
||
115 | * |
||
116 | * @return \Generator |
||
117 | */ |
||
118 | 1 | public function listImages(array $options = [], callable $mapFn = null): \Generator |
|
122 | 1 | ||
123 | /** |
||
124 | * Retrieve an image object without calling the remote API. Any values provided in the array will populate the |
||
125 | * empty object, allowing you greater control without the expense of network transactions. To call the remote API |
||
126 | * and have the response populate the object, call {@see Image::retrieve}. |
||
127 | * |
||
128 | * @param array $options An array of attributes that will be set on the {@see Image} object. The array keys need to |
||
129 | * correspond to the class public properties. |
||
130 | * |
||
131 | * @return \OpenStack\Compute\v2\Models\Image |
||
132 | */ |
||
133 | public function getImage(array $options = []): Image |
||
139 | |||
140 | /** |
||
141 | * List key pairs. |
||
142 | * |
||
143 | * @param array $options {@see \OpenStack\Compute\v2\Api::getKeyPairs} |
||
144 | * @param callable $mapFn A callable function that will be invoked on every iteration of the list. |
||
145 | * |
||
146 | * @return \Generator |
||
147 | */ |
||
148 | public function listKeypairs(array $options = [], callable $mapFn = null): \Generator |
||
152 | |||
153 | /** |
||
154 | * Create or import keypair |
||
155 | * |
||
156 | * @param array $options |
||
157 | * |
||
158 | * @return Keypair |
||
159 | */ |
||
160 | public function createKeypair(array $options): Keypair |
||
164 | |||
165 | /** |
||
166 | * Get keypair |
||
167 | * |
||
168 | * @param array $options |
||
169 | * |
||
170 | * @return Keypair |
||
171 | */ |
||
172 | public function getKeypair(array $options = []): Keypair |
||
178 | |||
179 | /** |
||
180 | * Shows rate and absolute limits for the tenant |
||
181 | * |
||
182 | * @return Limit |
||
183 | */ |
||
184 | public function getLimits(): Limit |
||
190 | |||
191 | /** |
||
192 | * Shows summary statistics for all hypervisors over all compute nodes. |
||
193 | * |
||
194 | * @return HypervisorStatistic |
||
195 | */ |
||
196 | public function getHypervisorStatistics(): HypervisorStatistic |
||
202 | } |
||
203 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: