1 | <?php |
||
14 | final class ProxyDriver implements DriverInterface |
||
15 | { |
||
16 | /** |
||
17 | * @var DriverInterface |
||
18 | */ |
||
19 | private static $instance; |
||
20 | |||
21 | /** |
||
22 | * Set driver instance to be used. |
||
23 | * |
||
24 | * @param DriverInterface $driver |
||
25 | */ |
||
26 | public static function setInstance(DriverInterface $driver) |
||
30 | |||
31 | /** |
||
32 | * @return DriverInterface |
||
33 | */ |
||
34 | private static function instance() |
||
42 | |||
43 | public function matchesRequest() |
||
47 | |||
48 | public function hasMatchingEvent() |
||
52 | |||
53 | public function getMessages() |
||
57 | |||
58 | public function isBot() |
||
62 | |||
63 | public function isConfigured() |
||
67 | |||
68 | public function getUser(IncomingMessage $matchingMessage) |
||
72 | |||
73 | public function getConversationAnswer(IncomingMessage $message) |
||
77 | |||
78 | public function buildServicePayload($message, $matchingMessage, $additionalParameters = []) |
||
82 | |||
83 | public function sendPayload($payload) |
||
87 | |||
88 | public function getName() |
||
92 | |||
93 | public function types(IncomingMessage $matchingMessage) |
||
97 | |||
98 | /** |
||
99 | * Tells if the stored conversation callbacks are serialized. |
||
100 | * |
||
101 | * @return bool |
||
102 | */ |
||
103 | public function serializesCallbacks() |
||
107 | |||
108 | /** |
||
109 | * Send a typing indicator and wait for the given amount of seconds. |
||
110 | * @param IncomingMessage $matchingMessage |
||
111 | * @param int $seconds |
||
112 | * @return mixed |
||
113 | */ |
||
114 | public function typesAndWaits(IncomingMessage $matchingMessage, int $seconds) |
||
118 | } |
||
119 |
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: