1 | <?php |
||
9 | class TwitterDeleteSerializer implements TwitterSerializer |
||
10 | { |
||
11 | /** |
||
12 | * @param TwitterSerializable $object |
||
13 | * @return \stdClass |
||
14 | */ |
||
15 | 12 | public function serialize(TwitterSerializable $object) |
|
47 | |||
48 | /** |
||
49 | * @param \stdClass $obj |
||
50 | * @param array $context |
||
51 | * @return TwitterDelete |
||
52 | */ |
||
53 | 6 | public function unserialize($obj, array $context = []) |
|
75 | |||
76 | 6 | /** |
|
77 | * @param TwitterSerializable $object |
||
78 | 6 | * @return boolean |
|
79 | */ |
||
80 | public function canSerialize(TwitterSerializable $object) |
||
84 | |||
85 | /** |
||
86 | * @param \stdClass $object |
||
87 | * @return boolean |
||
88 | */ |
||
89 | public function canUnserialize($object) |
||
93 | |||
94 | /** |
||
95 | * @return TwitterDeleteSerializer |
||
96 | */ |
||
97 | public static function build() |
||
101 | } |
||
102 |
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: