1 | <?php declare(strict_types=1); |
||
12 | class Resource extends OperatorResource implements Retrievable |
||
13 | { |
||
14 | const RESOURCE_TYPE_GENERIC = 'generic'; |
||
15 | |||
16 | /** @var string */ |
||
17 | public $createdByUserId; |
||
18 | |||
19 | /** @var string */ |
||
20 | public $startedAt; |
||
21 | |||
22 | /** @var string */ |
||
23 | public $displayName; |
||
24 | |||
25 | /** @var string */ |
||
26 | public $revisionEnd; |
||
27 | |||
28 | /** @var string */ |
||
29 | public $userId; |
||
30 | |||
31 | /** @var string */ |
||
32 | public $createdByProjectId; |
||
33 | |||
34 | /** @var string */ |
||
35 | public $id; |
||
36 | |||
37 | /** @var array */ |
||
38 | public $metrics; |
||
39 | |||
40 | /** @var string */ |
||
41 | public $host; |
||
42 | |||
43 | /** @var string */ |
||
44 | public $imageRef; |
||
45 | |||
46 | /** @var string */ |
||
47 | public $flavorId; |
||
48 | |||
49 | /** @var string */ |
||
50 | public $serverGroup; |
||
51 | |||
52 | /** @var string */ |
||
53 | public $originalResourceId; |
||
54 | |||
55 | /** @var string */ |
||
56 | public $revisionStart; |
||
57 | |||
58 | /** @var string */ |
||
59 | public $projectId; |
||
60 | |||
61 | /** @var string */ |
||
62 | public $type; |
||
63 | |||
64 | /** @var string */ |
||
65 | public $endedAt; |
||
66 | |||
67 | protected $aliases = [ |
||
68 | 'created_by_user_id' => 'createdByUserId', |
||
69 | 'started_at' => 'startedAt', |
||
70 | 'display_name' => 'displayName', |
||
71 | 'revision_end' => 'revisionEnd', |
||
72 | 'user_id' => 'userId', |
||
73 | 'created_by_project_id' => 'createdByProjectId', |
||
74 | 'image_ref' => 'imageRef', |
||
75 | 'flavor_id' => 'flavorId', |
||
76 | 'server_group' => 'serverGroup', |
||
77 | 'original_resource_id' => 'originalResourceId', |
||
78 | 'revision_start' => 'revisionStart', |
||
79 | 'project_id' => 'projectId', |
||
80 | 'ended_at' => 'endedAt', |
||
81 | ]; |
||
82 | |||
83 | public function retrieve() |
||
88 | |||
89 | /** |
||
90 | * @param string $metric |
||
91 | * |
||
92 | * @return Metric |
||
93 | */ |
||
94 | public function getMetric(string $metric): Metric |
||
108 | |||
109 | /** |
||
110 | * @param array $options {@see \OpenStack\Metric\v1\Gnocchi\Api::getResourceMetricMeasures} |
||
111 | * |
||
112 | * @return array |
||
113 | */ |
||
114 | public function getMetricMeasures(array $options = []): array |
||
128 | |||
129 | /** |
||
130 | * @param array $options {@see \OpenStack\Metric\v1\Gnocchi\Api::getResourceMetrics} |
||
131 | * |
||
132 | * @return \Generator |
||
133 | */ |
||
134 | public function listResourceMetrics(array $options = []): \Generator |
||
140 | } |
||
141 |
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: