1 | <?php declare(strict_types=1); |
||
18 | class LoadBalancer extends OperatorResource implements Creatable, Retrievable, Updateable, Deletable |
||
19 | { |
||
20 | /** |
||
21 | * @var string |
||
22 | */ |
||
23 | public $name; |
||
24 | |||
25 | /** |
||
26 | * @var string |
||
27 | */ |
||
28 | public $description; |
||
29 | |||
30 | /** |
||
31 | * @var boolean |
||
32 | */ |
||
33 | public $adminStateUp; |
||
34 | |||
35 | /** |
||
36 | * @var string |
||
37 | */ |
||
38 | public $tenantId; |
||
39 | |||
40 | /** |
||
41 | * @var LoadBalancerListener[] |
||
42 | */ |
||
43 | public $listeners; |
||
44 | |||
45 | /** |
||
46 | * @var string |
||
47 | */ |
||
48 | public $vipAddress; |
||
49 | |||
50 | /** |
||
51 | * @var string |
||
52 | */ |
||
53 | public $vipSubnetId; |
||
54 | |||
55 | /** |
||
56 | * @var string |
||
57 | */ |
||
58 | public $id; |
||
59 | |||
60 | /** |
||
61 | * @var string |
||
62 | */ |
||
63 | public $operatingStatus; |
||
64 | |||
65 | /** |
||
66 | * @var string |
||
67 | */ |
||
68 | public $provisioningStatus; |
||
69 | |||
70 | protected $resourcesKey = 'loadbalancers'; |
||
71 | protected $resourceKey = 'loadbalancer'; |
||
72 | |||
73 | protected $aliases = [ |
||
74 | 'tenant_id' => 'tenantId', |
||
75 | 'admin_state_up' => 'adminStateUp', |
||
76 | 'vip_address' => 'vipAddress', |
||
77 | 'vip_subnet_id' => 'vipSubnetId', |
||
78 | 'operating_status' => 'operatingStatus', |
||
79 | 'provisioning_status' => 'provisioningStatus', |
||
80 | ]; |
||
81 | |||
82 | /** |
||
83 | * @inheritdoc |
||
84 | */ |
||
85 | protected function getAliases(): array |
||
86 | { |
||
87 | return parent::getAliases() + [ |
||
88 | 'listeners' => new Alias('listeners', LoadBalancerListener::class, true) |
||
89 | ]; |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * {@inheritDoc} |
||
94 | */ |
||
95 | public function create(array $userOptions): Creatable |
||
100 | |||
101 | /** |
||
102 | * {@inheritDoc} |
||
103 | */ |
||
104 | public function retrieve() |
||
109 | |||
110 | /** |
||
111 | * {@inheritDoc} |
||
112 | */ |
||
113 | public function update() |
||
118 | |||
119 | /** |
||
120 | * {@inheritDoc} |
||
121 | */ |
||
122 | public function delete() |
||
126 | |||
127 | /** |
||
128 | * Add a listener to this load balancer |
||
129 | * |
||
130 | * @param array $userOptions |
||
131 | * @return LoadBalancerListener |
||
132 | */ |
||
133 | public function addListener(array $userOptions = []): LoadBalancerListener |
||
138 | |||
139 | /** |
||
140 | * Get stats for this loadbalancer |
||
141 | * |
||
142 | * @return LoadBalancerStat |
||
143 | */ |
||
144 | public function getStats(): LoadBalancerStat |
||
150 | |||
151 | /** |
||
152 | * Get the status tree for this loadbalancer |
||
153 | * |
||
154 | * @return LoadBalancerStatus |
||
155 | */ |
||
156 | public function getStatuses(): LoadBalancerStatus |
||
162 | } |
||
163 |
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: