1 | <?php |
||
8 | class Twilio |
||
9 | { |
||
10 | /** |
||
11 | * @var TwilioService |
||
12 | */ |
||
13 | protected $twilioService; |
||
14 | |||
15 | /** |
||
16 | * @var TwilioConfig |
||
17 | */ |
||
18 | private $config; |
||
19 | |||
20 | /** |
||
21 | * Twilio constructor. |
||
22 | * |
||
23 | * @param TwilioService $twilioService |
||
24 | * @param TwilioConfig $config |
||
25 | */ |
||
26 | 13 | public function __construct(TwilioService $twilioService, TwilioConfig $config) |
|
31 | |||
32 | /** |
||
33 | * Send a TwilioMessage to the a phone number. |
||
34 | * |
||
35 | * @param TwilioMessage $message |
||
36 | * @param string $to |
||
37 | * @param bool $useAlphanumericSender |
||
38 | * @return mixed |
||
39 | * @throws CouldNotSendNotification |
||
40 | */ |
||
41 | 11 | public function sendMessage(TwilioMessage $message, $to, $useAlphanumericSender = false) |
|
61 | |||
62 | /** |
||
63 | * Send an sms message using the Twilio Service. |
||
64 | * |
||
65 | * @param TwilioSmsMessage $message |
||
66 | 8 | * @param string $to |
|
67 | * @return \Twilio\Rest\Api\V2010\Account\MessageInstance |
||
68 | * @throws CouldNotSendNotification |
||
69 | 8 | */ |
|
70 | 7 | protected function sendSmsMessage(TwilioSmsMessage $message, $to) |
|
98 | |||
99 | /** |
||
100 | * Send an notify message uing the Twilio service |
||
101 | * |
||
102 | * @param TwilioNotifyMessage $message |
||
103 | 2 | * @param string $to |
|
104 | * @return \Twilio |
||
105 | */ |
||
106 | 2 | protected function notifyMessage(TwilioNotifyMessage $message, $to) |
|
119 | 2 | ||
120 | 2 | /** |
|
121 | * Make a call using the Twilio Service. |
||
122 | 2 | * |
|
123 | * @param TwilioCallMessage $message |
||
124 | * @param string $to |
||
125 | * @return \Twilio\Rest\Api\V2010\Account\CallInstance |
||
126 | * @throws CouldNotSendNotification |
||
127 | */ |
||
128 | protected function makeCall(TwilioCallMessage $message, $to) |
||
149 | 2 | ||
150 | /** |
||
151 | * Get the from address from message, or config. |
||
152 | * |
||
153 | * @param TwilioMessage $message |
||
154 | * @return string |
||
155 | * @throws CouldNotSendNotification |
||
156 | */ |
||
157 | protected function getFrom(TwilioMessage $message) |
||
165 | 9 | ||
166 | 9 | /** |
|
167 | * Get the alphanumeric sender from config, if one exists. |
||
168 | * |
||
169 | * @return string|null |
||
170 | */ |
||
171 | protected function getAlphanumericSender() |
||
177 | |||
178 | /** |
||
179 | * get service sid |
||
180 | * |
||
181 | * @param TwilioMessage $message |
||
182 | * @return string |
||
183 | * @throws CouldNotSendNotification |
||
184 | */ |
||
185 | protected function getServiceSid(TwilioMessage $message) |
||
195 | |||
196 | /** |
||
197 | * @param array $params |
||
198 | * @param TwilioMessage $message |
||
199 | * @param array $optionalParams |
||
200 | * @return mixed |
||
201 | */ |
||
202 | protected function fillOptionalParams(&$params, $message, $optionalParams) |
||
210 | } |
||
211 |
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 sub-classes 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 parent class: