1 | <?php |
||
15 | class Sms implements SmsProviderServicesInterface |
||
16 | { |
||
17 | /** |
||
18 | * @var SmsProviderServicesInterface |
||
19 | */ |
||
20 | private $smsProvider; |
||
21 | |||
22 | /** |
||
23 | * Sms constructor. |
||
24 | * @param SmsProviderServicesInterface|null $smsProvider |
||
25 | */ |
||
26 | public function __construct(SmsProviderServicesInterface $smsProvider = null) |
||
27 | { |
||
28 | // If no provider is specified, randomize by distribution percentage. |
||
29 | if ($smsProvider instanceof SmsProviderServicesInterface) { |
||
30 | $this->smsProvider = $smsProvider; |
||
31 | } else { |
||
32 | $provider = 'ridvanbaluyos\\sms\\providers\\' . $this->randomizeProvider(); |
||
33 | $this->smsProvider = new $provider(); |
||
34 | } |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * This function sends the SMS. |
||
39 | * |
||
40 | * @param $phoneNumber - the mobile number |
||
41 | * @param $message - the message |
||
42 | */ |
||
43 | public function send($phoneNumber, $message) |
||
48 | |||
49 | /** |
||
50 | * This function gets the remaining balance of an account |
||
51 | * |
||
52 | */ |
||
53 | public function balance() |
||
57 | |||
58 | /** |
||
59 | * This function randomizes the SMS providers. Make sure that the total |
||
60 | * of the SMS providers in distribution.json is equal to 1. Otherwise, there's |
||
61 | * no guarantee that the randomizer will work as expected. |
||
62 | * |
||
63 | * @return string $result - the lucky SMS provider |
||
64 | */ |
||
65 | private function randomizeProvider() |
||
80 | |||
81 | /** |
||
82 | * This function generates a random string with a specific length. |
||
83 | * |
||
84 | * @param int $length - the length of the message id |
||
85 | * @return string - returns a random n length string |
||
86 | */ |
||
87 | protected function generateMessageId($length = 32) |
||
91 | |||
92 | /** |
||
93 | * This function acts a pseudo-envelope for the responses of each SMS providers. It basically |
||
94 | * standardizes the responses of each. |
||
95 | * |
||
96 | * @param $code - the response code |
||
97 | * @param null $message - an optional message aside from the default ones |
||
98 | * @param null $provider - the SMS provider used. Should only be enabled during debug mode. |
||
99 | * |
||
100 | * @return string $response - the JSON formatted response. |
||
101 | */ |
||
102 | protected function response($code, $metadata = null, $message = null, $provider) |
||
162 | |||
163 | /** |
||
164 | * This function reformats the mobile number being sent to the Philippine mobile number standard. |
||
165 | * |
||
166 | * @param $number - the mobile number |
||
167 | * @return string - the formatted mobile number |
||
168 | */ |
||
169 | protected function prepareNumber($number) |
||
180 | |||
181 | /** |
||
182 | * This function returns the SMS Provider name in plain text. |
||
183 | * |
||
184 | * @return string $className - the sms provider name. |
||
185 | */ |
||
186 | public function getSmsProviderName() |
||
190 | } |
||
191 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: