| 1 | <?php |
||
| 9 | class TwitterEntityIndicesSerializer implements TwitterSerializer |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @param TwitterSerializable $object |
||
| 13 | * @return array |
||
| 14 | */ |
||
| 15 | 6 | public function serialize(TwitterSerializable $object) |
|
| 23 | |||
| 24 | /** |
||
| 25 | * @param array $array |
||
| 26 | * @param array $context |
||
| 27 | * @return TwitterEntityIndices |
||
| 28 | */ |
||
| 29 | 3 | public function unserialize($array, array $context = []) |
|
| 37 | 39 | ||
| 38 | /** |
||
| 39 | 39 | * @param TwitterSerializable $object |
|
| 40 | * @return boolean |
||
| 41 | */ |
||
| 42 | public function canSerialize(TwitterSerializable $object) |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @param \stdClass $object |
||
| 49 | * @return boolean |
||
| 50 | */ |
||
| 51 | public function canUnserialize($object) |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @return TwitterEntityIndicesSerializer |
||
| 58 | */ |
||
| 59 | public static function build() |
||
| 63 | } |
||
| 64 |
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: