1 | <?php |
||
19 | class Image extends AbstractResource implements Creatable, Listable, Retrievable, Deletable |
||
20 | { |
||
21 | /** @var string */ |
||
22 | public $status; |
||
23 | |||
24 | /** @var string */ |
||
25 | public $name; |
||
26 | |||
27 | /** @var array */ |
||
28 | public $tags; |
||
29 | |||
30 | /** @var string */ |
||
31 | public $containerFormat; |
||
32 | |||
33 | /** @var \DateTimeImmutable */ |
||
34 | public $createdAt; |
||
35 | |||
36 | /** @var string */ |
||
37 | public $diskFormat; |
||
38 | |||
39 | /** @var \DateTimeImmutable */ |
||
40 | public $updatedAt; |
||
41 | |||
42 | /** @var string */ |
||
43 | public $visibility; |
||
44 | |||
45 | /** @var int */ |
||
46 | public $minDisk; |
||
47 | |||
48 | /** @var bool */ |
||
49 | public $protected; |
||
50 | |||
51 | /** @var string */ |
||
52 | public $id; |
||
53 | |||
54 | /** @var \GuzzleHttp\Psr7\Uri */ |
||
55 | public $fileUri; |
||
56 | |||
57 | /** @var string */ |
||
58 | public $checksum; |
||
59 | |||
60 | /** @var string */ |
||
61 | public $ownerId; |
||
62 | |||
63 | /** @var int */ |
||
64 | public $size; |
||
65 | |||
66 | /** @var int */ |
||
67 | public $minRam; |
||
68 | |||
69 | /** @var \GuzzleHttp\Psr7\Uri */ |
||
70 | public $schemaUri; |
||
71 | |||
72 | /** @var int */ |
||
73 | public $virtualSize; |
||
74 | |||
75 | private $jsonSchema; |
||
76 | |||
77 | protected $aliases = [ |
||
78 | 'container_format' => 'containerFormat', |
||
79 | 'created_at' => 'createdAt', |
||
80 | 'disk_format' => 'diskFormat', |
||
81 | 'updated_at' => 'updatedAt', |
||
82 | 'min_disk' => 'minDisk', |
||
83 | 'owner' => 'ownerId', |
||
84 | 'min_ram' => 'minRam', |
||
85 | 'virtual_size' => 'virtualSize', |
||
86 | ]; |
||
87 | |||
88 | 6 | public function populateFromArray(array $data) |
|
102 | |||
103 | 1 | public function create(array $data) |
|
108 | |||
109 | 3 | public function retrieve() |
|
114 | |||
115 | 2 | private function getSchema() |
|
124 | |||
125 | 2 | public function update(array $data) |
|
157 | |||
158 | 1 | public function delete() |
|
162 | |||
163 | 1 | public function deactivate() |
|
167 | |||
168 | 1 | public function reactivate() |
|
172 | |||
173 | 1 | public function uploadData(StreamInterface $stream) |
|
181 | |||
182 | 1 | public function downloadData() |
|
187 | |||
188 | 1 | public function addMember($memberId) |
|
192 | |||
193 | 1 | public function listMembers() |
|
197 | |||
198 | 1 | public function getMember($memberId) |
|
202 | } |
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: